container icon indicating copy to clipboard operation
container copied to clipboard

Registration at ChildContainer with other LifetimeManager

Open Lederilon opened this issue 4 years ago • 1 comments

I have a problem with migration from MicrosoftPractices.Unity to Unity 5.10.3.

I use construction like this, to change LifeTimeManager of already registered in parentContainer types.

var parentContainer = _unityContainer;
			_unityContainer = _unityContainer.CreateChildContainer();
			foreach (var registration in parentContainer.Registrations)
			{
				if (registration.LifetimeManager is ContainerControlledLifetimeManager || registration.RegisteredType == typeof(IUnityContainer))
				{
					continue;
				}

				_unityContainer.RegisterType(registration.RegisteredType, registration.MappedToType,	new ContainerControlledLifetimeManager());
			}

At parentContainer they are registered with PerResolveLifetimeManager, but at childContaner it should be ContainerControlledLifetimeManager.

It used to work at old version, but now childContainer cannot resolve types registered with RegisterFactory method at parentContainer.

Lederilon avatar Mar 11 '20 14:03 Lederilon

I would need a test case demonstrating the problem.

ENikS avatar Apr 22 '20 19:04 ENikS