Code through the pain Ladislav Mrnka's professional blog about software development

7Mar/117

If you have been using inversion of control containers for a while you have most probably used some object lifetime management. The lifetime management enables reuse of existing object instances for subsequent resolution. It should be also responsible for controlling how the container will release resolved instances.

Unity offers lifetime management as classes derived from LifetimeManager. Lifetime managers in Unity are created once for each type's registration (there is an exception which I will discuss later). Every time a UnityContainer wants to create a new object instance when resolving a type it first checks with that type's lifetime manager if an instance is available. If no instance is available, the container creates an instance based on the configured constructor and passes that instance to the lifetime manager.

The following text discusses built-in lifetime managers, their behavior and usage.

Posted on March 7, 2011 by Ladislav Mrnka
Filed under: Enterprise library
Continue reading