How to remove(unregister) registered instance from Unity mapping?

前端 未结 6 1859
野趣味
野趣味 2020-12-04 19:50

I meet one problem that i can\'t solve now. I have the following:

UnityHelper.DefaultContainer.RegisterInstance(typeof(IMyInterface), \"test\", instance);
         


        
6条回答
  •  半阙折子戏
    2020-12-04 20:19

    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.Name == name
                    && p.LifetimeManager.Type == typeof(ContainerControlledLifetimeManager)))
    {
        registration.LifetimeManager.RemoveValue();
    }
    

提交回复
热议问题