I meet one problem that i can\'t solve now. I have the following:
UnityHelper.DefaultContainer.RegisterInstance(typeof(IMyInterface), \"test\", instance);
>
Here is how I handled unregistering instances from a unity container
I needed to implement Add/Remove functionality like this:
public interface IObjectBuilder
{
void AddInstance(T instance);
void RemoveInstance(T instance);
}
I created a custom lifetime manager to do the implementation
public class ExplicitLifetimeManager :
LifetimeManager
{
object Value;
public override object GetValue()
{
return Value;
}
public override void SetValue(object newValue)
{
Value = newValue;
}
public override void RemoveValue()
{
Value = null;
}
}
Here is the final implementation:
Dictionary
calling removevalue on the custom lifetime manager causes the instance to be unregistered