Skip to content

Commit

Permalink
Added failing unit test for #1250
Browse files Browse the repository at this point in the history
  • Loading branch information
tillig committed Jan 26, 2021
1 parent 9a2d3a4 commit 5959987
Showing 1 changed file with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,26 @@ public void KeyFilterIsAppliedOnConstructorDependencyManyWithOwned()
Assert.Equal(2, resolved.Loggers.Count());
}

[Fact(Skip = "Issue #1250")]
public void KeyFilterIsAppliedOnMultipleIndividualConcreteDependencies()
{
// Issue #1250 - key filtering doesn't work on components keyed as themselves.
var builder = new ContainerBuilder();
builder.RegisterType<ConsoleLogger>().As<ILogger>();
builder.Register(ctx => new IdentifiableObject { Id = "a" }).Keyed<IdentifiableObject>("First");
builder.Register(ctx => new IdentifiableObject { Id = "b" }).Keyed<IdentifiableObject>("Second");
builder.Register(ctx => new IdentifiableObject { Id = "c" }).Keyed<IdentifiableObject>("Third");
builder.RegisterType<ManagerWithManyIndividualConcrete>();

var container = builder.Build();
var resolved = container.Resolve<ManagerWithManyIndividualConcrete>();

Assert.IsType<ConsoleLogger>(resolved.Logger);
Assert.Equal("a", resolved.First.Id);
Assert.Equal("b", resolved.Second.Id);
Assert.Equal("c", resolved.Third.Id);
}

[Fact]
public void MetadataFilterIsAppliedOnConstructorDependencySingle()
{
Expand Down Expand Up @@ -382,6 +402,34 @@ public class ToolWindowAdapter : IAdapter
{
}

public class IdentifiableObject
{
public string Id { get; set; }
}

public class ManagerWithManyIndividualConcrete
{
public ManagerWithManyIndividualConcrete(
ILogger logger,
[KeyFilter("First")] IdentifiableObject first,
[KeyFilter("Second")] IdentifiableObject second,
[KeyFilter("Third")] IdentifiableObject third)
{
Logger = logger;
First = first;
Second = second;
Third = third;
}

public ILogger Logger { get; set; }

public IdentifiableObject First { get; set; }

public IdentifiableObject Second { get; set; }

public IdentifiableObject Third { get; set; }
}

public class ManagerWithLazySingle
{
public ManagerWithLazySingle([KeyFilter("Manager")] Lazy<ILogger> logger)
Expand Down Expand Up @@ -516,4 +564,4 @@ public OptionalParameterWithKeyFilter([KeyFilter(0)] int parameter = 15)
}
}
}
}
}

0 comments on commit 5959987

Please sign in to comment.