Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hadashiA/VContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA committed Oct 9, 2020
2 parents 8bd35ff + 26248e6 commit 24970cc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VContainer/Assets/VContainer/Runtime/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public object Resolve(IRegistration registration)
{
return sharedInstances.GetOrAdd(registration, createInstance).Value;
}
return Parent.Resolve(registration);
return (Parent.Parent is null ? Parent.Root : Parent).Resolve(registration);

case Lifetime.Scoped:
var lazy = sharedInstances.GetOrAdd(registration, createInstance);
Expand Down
2 changes: 2 additions & 0 deletions VContainer/Assets/VContainer/Tests/ScopedContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ public void CreateScopeWithRegisterSingleton()
{
var parentSingleton = grandChildContainer.Resolve<NoDependencyServiceA>();
Assert.That(parentSingleton, Is.InstanceOf<NoDependencyServiceA>());
Assert.That(parentSingleton, Is.EqualTo(parentContainer.Resolve<NoDependencyServiceA>()));

var childSingleton = grandChildContainer.Resolve<ServiceA>();
Assert.That(childSingleton, Is.InstanceOf<ServiceA>());
Assert.That(childSingleton.Service2, Is.InstanceOf<I2>());
Assert.That(childSingleton, Is.EqualTo(childContainer.Resolve<ServiceA>()));

var grandChildSingleton = grandChildContainer.Resolve<ServiceB>();
Assert.That(grandChildSingleton, Is.InstanceOf<ServiceB>());
Expand Down

0 comments on commit 24970cc

Please sign in to comment.