|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using NUnit.Framework; |
| 5 | +using Microsoft.Extensions.DependencyInjection; |
| 6 | +using DryIoc.Microsoft.DependencyInjection; |
| 7 | + |
| 8 | +namespace DryIoc.IssuesTests |
| 9 | +{ |
| 10 | + public class GHIssue574_Cannot_register_multiple_impls_in_child_container_with_default_service_key |
| 11 | + { |
| 12 | + [Ignore("fixme")] |
| 13 | + public void ResolveEnumerableFromChild() |
| 14 | + { |
| 15 | + var services = new ServiceCollection(); |
| 16 | + |
| 17 | + services.AddScoped<IPrinter, Printer>(); |
| 18 | + services.AddScoped<IPrinter, PrinterA>(); |
| 19 | + services.AddScoped<IPrinter, PrinterB>(); |
| 20 | + services.AddScoped<IPrinter, NeighborPrinter>(); |
| 21 | + |
| 22 | + var spf = new DryIocServiceProviderFactory(); |
| 23 | + var rootContainer = spf.CreateBuilder(new ServiceCollection()); |
| 24 | + var childContainer = rootContainer.CreateChild(RegistrySharing.Share, "child-stamp", IfAlreadyRegistered.AppendNewImplementation); |
| 25 | + |
| 26 | + //childContainer.Populate(services); |
| 27 | + foreach (var service in services) |
| 28 | + { |
| 29 | + childContainer.RegisterDescriptor(service, IfAlreadyRegistered.AppendNewImplementation, "child-stamp"); |
| 30 | + } |
| 31 | + |
| 32 | + var msContainer = childContainer.GetServiceProvider(); |
| 33 | + |
| 34 | + Assert.That( |
| 35 | + childContainer.Resolve<IEnumerable<IPrinter>>().Count(), |
| 36 | + Is.EqualTo(msContainer.GetRequiredService<IEnumerable<IPrinter>>().Count())); |
| 37 | + |
| 38 | + Assert.That( |
| 39 | + msContainer.GetRequiredService<IEnumerable<IPrinter>>().Count(), |
| 40 | + Is.EqualTo(4)); |
| 41 | + } |
| 42 | + |
| 43 | + private interface IPrinter { } |
| 44 | + |
| 45 | + private class Printer : IPrinter { } |
| 46 | + |
| 47 | + private class PrinterA : IPrinter { } |
| 48 | + |
| 49 | + private class PrinterB : IPrinter { } |
| 50 | + |
| 51 | + private class NeighborPrinter : IPrinter { } |
| 52 | + } |
| 53 | +} |
0 commit comments