Reset singleton

Apr 16, 2012 at 8:59 AM


I have registered IService interface in my unity container as a singleton:

containerControlledLifetimeManager = new ContainerControlledLifetimeManager();
container.RegisterType<IService1, Service1>(containerControlledLifetimeManager);

Then the first time I resolve IService, a new Service object is created and reused in all the next resolve IService actions. But how could I reset this object in the container? I mean to call something like container.Reset<IService>() and, after this moment, the next IService resolve creates the Service object again.

Thanks in advance

Apr 16, 2012 at 9:23 AM

I think you need a custom LifetimeManager to do something like that. The ContainerControlledLifetimeManager holds a reference to the created object and returns that instance whenever an appropriate request is made to the container.