Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make conflict registration always resolve with the last one #191

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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