What's the equivalent of StructureMap's HttpContextScoped in SimpleInjector?

Sep 23, 2012 at 6:25 AM

I use these codes with structureMap but i cant find the equivalent of those in SimpleInjector:


x.For<IUnitOfWork>().HttpContextScoped().Use(() => new BlogContext());



protected void Application_EndRequest(object sender, EventArgs e)



Sep 23, 2012 at 6:54 AM
Edited Sep 23, 2012 at 1:16 PM

This is the Per Web Request lifestyle. There is a RegisterPerWebRequest extension method of the ASP.NET Integration NuGet Package for this. The equivalent would be:

container.RegisterPerWebRequest<IUnitOfWork>(() => new BlogContext());

Step two is not needed. The created BlogContext will be disposed automatically at the end of the request using the integration package.

Marked as answer by dot_NET_Junkie on 11/4/2013 at 2:02 AM