How to have n instances of a type with ContainerControlledLifetimeManager LifeTime

Jun 2, 2009 at 10:16 AM
Edited Jun 2, 2009 at 10:21 AM
How can I have n instances of a type with ContainerControlledLifetimeManager LifeTime ? Instances of A1 should be disposed when Container is Disposed. Instances of A1 are identified by a unique NAME
Jun 2, 2009 at 8:37 PM

Hi

 

If I understand correctly you want to have multiple instances of the same type registered in your container. If you are using Unity, you can achieve this by registering your objects in the container with a particular ID, through the RegisterInstance method. The ContainerControlledLifetimeManager is specifically used when you want the container to return always the same instance of the registered type.

 

 

The following articles from the Unity documentation show some examples to achieve this:

·         Registering Existing Object Instances

·         Using Lifetime Managers

 

If none of the life time managers included in the Unity Application Block suites your scenario, you can find more information about how you can create your own custom lifetime managers in Creating Lifetime Managers.

 

Please let me know if this helps.

 

Damian Schenkelman

http://blogs.southworks.net/dschenkelman