本文介绍了如何在StructureMap的ObjectFactory中处置每个实例对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用StructureMap,当应用程序完成运行时,我需要在ObjectFactory内实现IDisposable的所有Singleton实例上调用Dispose()方法.

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.

无论如何我都无法通过StructureMap API来做到这一点.

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.

推荐答案

我在另一个问题中找到了答案: StructureMap处置容器

I found the answer in another question: StructureMap Disposing Container

ObjectFactory.Container.Dispose();

这篇关于如何在StructureMap的ObjectFactory中处置每个实例对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:19