When to use ExternallyControlledLifetimeManager?

4.1k views Asked by At

I was going through different LifetimeManagers available in Unity and was wondering when will we use ExternallyControlledLifetimeManager? Can somebody give me an real life example? The MSDN doc says "A LifetimeManager that holds a weak reference to it's managed instance"..

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

1

There are 1 answers

0
onof On BEST ANSWER

It could be useful if you're going to register an object created by other frameworks or library and you haven't the control of its life, for example a singleton provided by a third-party library.

Because the container keeps only a weak reference, the GC will delete that singleton if there aren't any strong reference. IMO, you should use it only if you can't manage the life time of the instance.