开发者

StructureMap remove all disposed object references but leave configuration

Hy guys,

I am currently trying to implement some custom ILifecycles for StructureMap. Depending on events the lifecycle is associated with all object should be removed from the lifecycle.

Here is the registration for an object. I get a lifecycle from my manager for a plugintype and concretetype using a scope to determine the lifecycle.

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

I am using the LifecycleManager to keep knowledge of my objects, cos i need to check whether objects already exists and only create/return it if i pass 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 exist开发者_如何学Going instance
           if (doesInstanceExist)
           {
              container = DependencyInjectionContainer.GetInstance<T>();
           }
        }

After the object is done with its work or an associated event is fired the objects instance should be removed and disposed. My problem is, that i dont find a way to remove to references held by the StructureMap.Profile class, they always keep hanging around.

How can i remove all references to my objects but keep the configuration?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜