How can I dispose every instance object in StructureMap's ObjectFactory?

烂漫一生 提交于 2020-01-21 12:13:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!