-
-
Notifications
You must be signed in to change notification settings - Fork 72
Closed
Labels
masterIssue has been merged into ‘master’Issue has been merged into ‘master’releaseRelease branchRelease branch
Milestone
Description
Description
I have created unit container, registered open type as singleton and I am trying to resolve them in child containers and I got error: "System.InvalidOperationException: 'ContainerControlledLifetimeManager can only be set once'". I am expecting resolve of singleton services on different child containers will return same instance.
To Reproduce
Sample is bellow:
[Test]
public void Test()
{
IUnityContainer uc = new UnityContainer();
uc.RegisterSingleton(typeof(IBoo<>), typeof(Boo<>));
IBoo<object> boo1 = null;
IBoo<object> boo2 = null;
using (var scope = uc.CreateChildContainer())
{
boo1 = scope.Resolve<IBoo<object>>();
}
using (var scope = uc.CreateChildContainer())
{
boo2 = scope.Resolve<IBoo<object>>(); // Throws => System.InvalidOperationException: 'ContainerControlledLifetimeManager can only be set once'
}
NotNull(boo1);
NotNull(boo2);
AreEqual(boo1, boo2);
}
public interface IBoo<T>
{
}
public class Boo<T> : IBoo<T>
{
}karelkral, Audrunas, chemass and morsiu
Metadata
Metadata
Assignees
Labels
masterIssue has been merged into ‘master’Issue has been merged into ‘master’releaseRelease branchRelease branch