问题
I'm using StructureMap in my project and when the application finishes running I need to call the Dispose() method on all of the Singleton instances inside the ObjectFactory that implement IDisposable.
I cannot find anyway to do it via the StructureMap API.
Another thought I had was to get a reference to every instance and call it myself, but I cannot figure out how to loop through all of the instances.
回答1:
PS: You might be interested in the deterministic disposal by Autofac IoC container
Autofac can guarantee that components are disposed of predictably.
回答2:
I found the answer in another question: StructureMap Disposing Container
ObjectFactory.Container.Dispose();
来源:https://stackoverflow.com/questions/354354/how-can-i-dispose-every-instance-object-in-structuremaps-objectfactory