I'm currently working with ASP.net MVC with repository pattern, the problem arise when we need to audit each entity.
I decided to utilize the change tracking feature which can track down the entity activity, the problem is when we need to involve several repository with it's private context object in one controller which is not supported by entity change tracker.
public SalesOrderController(INumberingRepository NumberRepository, IProductRepository ProductRepository, ISalesOrderRepository SalesOrderRepository)
this.productRepository = ProductRepository;
this.salesOrderRepository = SalesOrderRepository;
this.numberRepository = NumberRepository;
whereby each repository has it's own context.
is there any reference design so that entity framework change tracker feature can work happily with multiple repository context ?
If you have your context object life cycle set to Per HttpRequest through IoC,then you can perform all of the database calls as one transaction per HttpRequest and per .SaveChanges(). And instead of private context per Repository, inject context into Repositories.
In case of Structuremaps,
For<DbContext>().LifecycleIs(new HybridLifecycle()).Use(c=> new DbContext());