存储库和事务

时间:2017-06-02 14:47:59

标签: c# software-design

在我的项目中,我有很多存储库。每个存储库都可以使用不同的数据库例如,AuthRepository与ProjectName.Auth数据库一起使用,SubscriptionsRepository与ProjectName.Subscriptions数据库等一起工作。如果用户调用方法,使用两个存储库,其中一些将抛出异常怎么办?例如:

private void InspectionDataGridViewCellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        ContextMenu m = new ContextMenu();

        int currentRow = e.RowIndex;
            if (this.currentInspection != null) // the row that is being right-clicked might not be the row that is selected.
            {
                var MI = new MenuItem(string.Format("Mark inspection point {0} as complete.", this.currentInspection.InspectionNumber), this.markInspectionPointComplete)
                MI.Tag = e;
                m.MenuItems.Add(MI);
            }
        m.Show(this.InspectionDataGridView, new Point(e.X,e.Y));
    }
}

private void markInspectionPointComplete(object sender, EventArgs e)
{
    var MI = (MenuItem)sender;
    DataGridViewCellMouseEventArgs Obj = (DataGridViewCellMouseEventArgs) MI.Tag;

    // Do whatever you want with your Obj

    MessageBox.Show("the right-click menu works.");
}

我该如何处理?正如我之前所说,我使用了很多存储库,所以我不知道如何在这里使用事务,因为每个存储库都可以使用不同的数据库。

0 个答案:

没有答案