在多个DAL类

时间:2017-11-29 14:36:32

标签: c# entity-framework

我希望多于一个DAL类将使用BLL中相同的Entity Framework dbContext来处理事务并避免一直创建dbContext。

因此,我正在使用我的ContextHolder类,它将保存dbContext的引用。我想做这样的事情:

using (var contextHolder= new DAL.contextHolder()) //Here i create an instance for the real DBContext and pass it as a reference to every dal function i have

            {

                var dalAdminUsers = new JungleDAL.AdminUsers(contextHolder); 
                dalAdminUsers.DoSomething();

                var dalCustomers = new JungleDAL.Customers(contextHolder);
                dalCustomers .DoSomething();

            }// Here i want to dispose my ContextHolder that should dispose in his turn the DBContext.

从BLL函数共享相同的Entity Framework dbContext是否正确?

0 个答案:

没有答案