Lifetime of components

Feb 19, 2010 at 11:12 AM
Edited Feb 19, 2010 at 11:13 AM



We are planning to use Unity in our application and have found this really amazing. Wanted to clear a doubt prior to using Unity, how does Unity manage running instances of components.

Suppose I have an instance of a class running ( in our case it would be a server), which responds to requests. Suppose some exception occurs in this component and it stops running. So how will Unity manage an instance of this component. The next client request will not start or "resolve" dependency with the server. So does Unity re-initializes such components by itself, coz we need one instance of the server running always. Is it done automatically by ContainerControlledLifetimeManager?

Would appreciate any advice.




Feb 20, 2010 at 7:13 PM

Unity doesn't do anything other than create an object when it's needed, and (if configured as such) dispose the object when the container is disposed. In particular, there's no definition of "running" that I know of other than the COM+ sense of the word, and that's a much bigger system than what we do.

I could see a custom lifetime manager that knows how to check if an object is still "running" and, if not, cause a new one to be created, but you'd have to write it custom based on your requirements.