We have a standard "chain" of modules that MVC3 controller creates and calls (directly or indirectly) - "MyController" -> "MyService" -> "MyRepository" -> "MyUnitOfWork"
The modules are registered in App_Start as following:
var builder = new ContainerBuilder();
builder.RegisterType<MyRepository>().AsImplementedInterfaces().InstancePerHttpRequest();
builder.RegisterType<MyUnitOfWork>().AsSelf().InstancePerHttpRequest();
builder.RegisterType<MyService>().AsImplementedInterfaces().InstancePerHttpRequest();
IContainer container = builder.Build();
DependencyResolver.SetResolver( new AutofacDependencyResolver( container ) );
When we try to perform multiple calls to the service from the controller in parallel, we're getting exceptions in EF4 (we use DbContext as a base class for UoW).
What would be a correct scoping of the modules to make parallel calls to service in the context of the same HttpRequest?
Thank you :)
Sounds like 1 DbContext per HttpRequest isn't gonna work for you. You probably need InstancePerDependency() and then request a new DbContext per thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With