2

嗨,伙计们,

我目前正在尝试为 StructureMap 实现一些自定义 ILifecycle。根据事件,生命周期与所有对象相关联应从生命周期中删除。

这是对象的注册。我从我的经理那里得到一个插件类型和具体类型的生命周期,使用范围来确定生命周期。

registry.For(pluginType)
              .LifecycleIs(_lifecycleManager.GetLifecycle(pluginType, instance.GetType(), lifecycleScope))
              .Use(instance);

我正在使用 LifecycleManager 来了解我的对象,因为我需要检查对象是否已经存在,并且只有在我通过 createIfMissing = true 时才创建/返回它。

        // determine if an instance already exists for the plugin type
        bool doesInstanceExist = _lifecycleManager.ContainsInstance(pluginType);

        if (createIfMissing)
        {
           // create a new instance or get an already existing one
           container = DependencyInjectionContainer.GetInstance<T>();
        }
        else
        {
           // only get an existing instance
           if (doesInstanceExist)
           {
              container = DependencyInjectionContainer.GetInstance<T>();
           }
        }

在对象完成其工作或触发相关事件后,应删除并处置对象实例。我的问题是,我找不到删除对 StructureMap.Profile 类持有的引用的方法,它们总是在附近徘徊。

如何删除对我的对象的所有引用但保留配置?

4

0 回答 0