Reputation: 733
Using the Unity.Mvc3 with a Mvc 3 application, i could register my IDummyService
as follows:
container.RegisterType<IDummyService, DummyService>(new HierarchicalLifetimeManager());
On each web request, a new instance of my IDummyService
is created (as explained in this article), but since I upgraded Mvc 3 to Mvc 4 and hense Unity.Mvc3 to Unity.Mvc, an single instance is created and used across all web requests, untill restarting the app. Basically, IDummyService
is a singleton in a Mvc 4 application when using HierarchicalLifetimeManager
. For me this is hard to believe this is intended new behavior in Unity.Mvc.
Is there a better explanations for this?
Upvotes: 4
Views: 515
Reputation: 5578
Unity.Mvc3 and Unity.Mvc are created by two different organizations and have different implementations.
Unity.Mvc3 creates a child container per web request. This works well with the built-in HierarchicalLifetimeManager
.
Unity.Mvc does not create a child container, but instead chose to create a new LifetimeManager called PerRequestLifetimeManager
.
Upvotes: 5