Skip to content

Commit

Permalink
Merge pull request #191 from hadashiA/ku/resolve-last-one
Browse files Browse the repository at this point in the history
Make conflict registration always resolve with the last one
  • Loading branch information
hadashiA authored Apr 23, 2021
2 parents a7d8065 + 051c2da commit 5f101a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ static void AddToBuildBuffer(IDictionary<Type, IRegistration> buf, Type service,
AddCollectionToBuildBuffer(buf, collection);
}
collection.Add(registration);

// Overwritten by the later registration
buf[service] = registration;
}
else
{
Expand Down
18 changes: 18 additions & 0 deletions VContainer/Assets/VContainer/Tests/ContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ public void ResolveCollection()
Assert.That(empty, Is.Empty);
}

[Test]
public void ResolveLastOneWhenConflicted()
{
var builder = new ContainerBuilder();
builder.Register<I1, MultipleInterfaceServiceA>(Lifetime.Transient);
builder.Register<I1, MultipleInterfaceServiceB>(Lifetime.Transient);

builder.Register<I3, MultipleInterfaceServiceB>(Lifetime.Transient);
builder.Register<I3, MultipleInterfaceServiceA>(Lifetime.Transient);
builder.Register<I3, MultipleInterfaceServiceB>(Lifetime.Transient);

var container = builder.Build();
var i1 = container.Resolve<I1>();
var i3 = container.Resolve<I3>();
Assert.That(i1, Is.InstanceOf<MultipleInterfaceServiceB>());
Assert.That(i3, Is.InstanceOf<MultipleInterfaceServiceB>());
}

[Test]
public void ResolveOnceAsCollection()
{
Expand Down

1 comment on commit 5f101a2

@vercel
Copy link

@vercel vercel bot commented on 5f101a2 Apr 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.