从Unity映射如何删除(注销)注册实例 [英] How to remove(unregister) registered instance from Unity mapping
问题描述
我满足我现在不能解决一个问题。
我有以下几点:
UnityHelper.DefaultContainer.RegisterInstance(typeof运算(IMyInterface的),测试,实例) ;
其中, UnityHelper.DefaultContainer
是我的助手越来越团结容器装配置。
在这里我注册了实例
作为实例 IMyInterface的
。
所以,任何地方(一段时间后使用),我想删除这个映射。删除它。 ?我该怎么办呢 p>
我曾尝试:
UnityHelper .DefaultContainer.Teardown(实例)
但不成功而下面的代码返回实例
反正:
UnityHelper.DefaultContainer.ResolveAll< IMyInterface的>()
我有同样的问题,只是删除了<$ C $的注册C> ContainerControlledLifetimeManager 从我集装箱
:
的foreach(在container.Registrations
。凡VAR登记(p => p.RegisteredType == typeof运算(对象)
和;&安培; p.LifetimeManagerType == typeof运算(ContainerControlledLifetimeManager)))
{
registration.LifetimeManager.RemoveValue();
}
I meet one problem that i can't solve now. I have the following:
UnityHelper.DefaultContainer.RegisterInstance(typeof(IMyInterface), "test", instance);
where UnityHelper.DefaultContainer
is my helper for getting unity container with loaded configuration.
here I registered instance
as an instance of IMyInterface
.
So anywhere( some time after using) I want to remove this mapping. Remove it at all. How I can do it?
I have tried:
UnityHelper.DefaultContainer.Teardown(instance)
but is was unsuccessful and the following code returns instance
anyway:
UnityHelper.DefaultContainer.ResolveAll<IMyInterface>()
I had the same problem and just removed the registrations of the ContainerControlledLifetimeManager
from my Container
:
foreach (var registration in container.Registrations
.Where(p => p.RegisteredType == typeof(object)
&& p.LifetimeManagerType == typeof(ContainerControlledLifetimeManager)))
{
registration.LifetimeManager.RemoveValue();
}
这篇关于从Unity映射如何删除(注销)注册实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!