How can I dispose every instance object in StructureMap's ObjectFactory?
-
21-08-2019 - |
Question
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.
Solution 2
I found the answer in another question: StructureMap Disposing Container
ObjectFactory.Container.Dispose();
OTHER TIPS
PS: You might be interested in the deterministic disposal by Autofac IoC container
Autofac can guarantee that components are disposed of predictably.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow