[Fact]
public void Should_Resolve_Registered_Enumerable()
{
var collection = new ServiceCollection();
collection.AddSingleton((IEnumerable<MyTestClass3>) new List<MyTestClass3>
{
new MyTestClass3(),
new MyTestClass3(),
new MyTestClass3()
});
var serviceProvider = CreateServiceProvider(collection);
using (var scope = serviceProvider.CreateScope())
{
var singletonEnumerable = scope.ServiceProvider.GetService<IEnumerable<MyTestClass3>>();
var list = singletonEnumerable.ToList();
list.Count.ShouldBe(3);
}
}
We directly registered IEnumerable (instead of multiple implementation of MyTestClass3). This test can not pass since it tries to return multiple implementation of MyTestClass3 as first, and can not find!
See unit test:
We directly registered IEnumerable (instead of multiple implementation of MyTestClass3). This test can not pass since it tries to return multiple implementation of MyTestClass3 as first, and can not find!