Lifetime Managers in Unity Container
The unity container manages the lifetime of objects of all the dependencies that it resolves using lifetime managers.Unity container includes different lifetime managers for different purposes. You can specify lifetime manager in RegisterType() method at the time of registering type-mapping.
Lifetime Manager | Description |
---|---|
TransientLifetimeManager | When no lifetime manager is defined, unity defaults to Transient.
Creates a new object of requested type every time you call Resolve or ResolveAll method. |
ContainerControlledLifetimeManager | Creates a singleton object first time you call Resolve or ResolveAll method and then returns the same object on subsequent Resolve or ResolveAll call. |
HierarchicalLifetimeManager | Same as ContainerControlledLifetimeManager, the only difference is that child container can create its own singleton object. Parent and child container do not share singleton object. |
PerResolveLifetimeManager | Similar to TransientLifetimeManager but it reuses the same object of registered type in the recursive object graph. |
PerThreadLifetimeManager | Creates singleton object per thread basis. It returns different objects from the container on different threads. |
ExternallyControlledLifetimeManager | It manintains only weak reference of objects it creates when you call Resolve or ResolveAll method. It does not maintain the lifetime of strong objects it creates and allow you or garbage collector to control the lifetime. It enables you to create your own custom lifetime manager |
my thanks to:
http://www.tutorialsteacher.com/ioc/lifetime-manager-in-unity-container
0 comments:
Post a Comment