Everything,
There have been many reports of Unity Lifetime Managers, but I have not yet found that someone claims a good rule of thumb: "In these cases, you should always use X." Let me describe my application, I have an ASP.NET MVC 4 web application. I have a Visual Studio solution containing 3 projects, my "Core" project, which has all my EF materials, a testing project, and an MVC Web Project. I am using Unity for dependency injection and have the following code right now:
// Context container.RegisterType<IDatabaseFactory, DatabaseFactory>( new ContainerControlledLifetimeManager(); container.RegisterType<UnitOfWork>( new ContainerControlledLifetimeManager());
However, I notice that my context is not recreated with every new web request that I think I need (let me know if I am mistaken in this assumption). I find it difficult to analyze all the information from the sites listed below and read that many people create their own class called PerHttpRequestLifetimeManager to handle this.
What is really best practice?
Kwondra
source share