Unity 2 and ObjectBuilder2.Locator

Jul 14, 2010 at 2:24 PM
I have a class that inherits from ObjectBuilder2.Locator class in Enterprise Library 4.1. The intended use was to provide weak references to "Entities" in our projects. In Unity 2.0, this class is no longer available and I haven't been able to find what it was replaced with. 1. Is there an equivelant class in Unity 2? 2. Should I be looking to do weak references differently in Unity 2? I just need some direction on what this class was replaced with. Thanks jeff
Jul 14, 2010 at 6:13 PM

The class was completely removed, and not replaced with anything because it turned out we weren't actually using it and it caused all sorts of confusion and bugs.

If you're storing the objects in the UnityContainer, you can use ExternallyControlledLifetimeManager instead. If you just need a weak dictionary, you can grab the code from the ObjectBuilder2 codebase (shipped with Unity 1.2) and rip it out; it's pretty standalone.

 

Jul 14, 2010 at 8:16 PM

Thanks for the reply.  I went down the Container way.  I would prefer not to use the copy code method but in reality, all I am after is the weak dictionary.

The code I am using is below:

_container.RegisterInstance<T>(key, value, new ExternallyControlledLifetimeManager()); 

Now the only functionality I am missing is the Remove

_container.RemoveInstance<T>(key, value, new ExternallyControlledLifetimeManager()); 

In reading the other discussions, it looks like this is intentionally left out.  So my question is what is the work around. 

Basically what I am doing is storing weak references to my Entities for EntityTracking.  Once something is Deleted from the Database, I am wanting to remove that reference.  I want _container.Resolve<T>(key) to return null.

I was thinking I could hack this by calling _container.RegisterInstance<T>(key, null, new Externally...));

What are your thoughts?

Thanks for the help!

jeff