StructureMap removes all references to remote objects but leaves the configuration

Guy wang,

I am currently trying to implement some custom ILifecycles for StructureMap. Based on events, the lifecycle is associated with the entire object that must be removed from the lifecycle.

Here is the registration of the object. I am getting lifecycle from my manager for plugintype and concretetype using scope to define lifecycle.

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

      

I use LifecycleManager to store knowledge about my objects because I need to check if the objects already exist 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 existing instance
           if (doesInstanceExist)
           {
              container = DependencyInjectionContainer.GetInstance<T>();
           }
        }

      

After the object completes its work or the corresponding event is fired, the object instance must be deleted and disposed of. My problem is that I don't find a way to remove the references stored in the StructureMap.Profile class, they always keep wagging.

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

+2


a source to share





All Articles