When to use ExternallyControlledLifetimeManager?

I was going through the different LifetimeManagers available in Unity and wondering when we will use the ExternallyControlledLifetimeManager? Can someone give me an example of real life? The MSDN document says: "A LifetimeManager that has a weak link to a managed instance."

How can a developer manage an instance, and when should he go for such a life manager? Your thoughts on how and when you used it would be good for me and others to understand. Thanks!

+8
asp.net-mvc unity-container enterprise-library enterprise-library-5
source share
1 answer

This can be useful if you are going to register an object created by other frameworks or a library, and you do not control its life, for example, a singleton provided by a third-party library.

Since the container retains only a weak link, GC will remove this singleton if there is no strong link. IMO, you should use it only if you cannot control the lifetime of the instance.

+11
source share

All Articles