Skip to content

Commit

Permalink
Merge pull request #575 from Amleto/gh-issue-574
Browse files Browse the repository at this point in the history
Add failing test for Gh issue #574
  • Loading branch information
dadhi authored May 10, 2023
2 parents 497e84f + 6f8a6da commit 45a60f4
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Microsoft.Extensions.DependencyInjection;
using DryIoc.Microsoft.DependencyInjection;

namespace DryIoc.IssuesTests
{
public class GHIssue574_Cannot_register_multiple_impls_in_child_container_with_default_service_key
{
[Ignore("fixme")]
public void ResolveEnumerableFromChild()
{
var services = new ServiceCollection();

services.AddScoped<IPrinter, Printer>();
services.AddScoped<IPrinter, PrinterA>();
services.AddScoped<IPrinter, PrinterB>();
services.AddScoped<IPrinter, NeighborPrinter>();

var spf = new DryIocServiceProviderFactory();
var rootContainer = spf.CreateBuilder(new ServiceCollection());
var childContainer = rootContainer.CreateChild(RegistrySharing.Share, "child-stamp", IfAlreadyRegistered.AppendNewImplementation);

//childContainer.Populate(services);
foreach (var service in services)
{
childContainer.RegisterDescriptor(service, IfAlreadyRegistered.AppendNewImplementation, "child-stamp");
}

var msContainer = childContainer.GetServiceProvider();

Assert.That(
childContainer.Resolve<IEnumerable<IPrinter>>().Count(),
Is.EqualTo(msContainer.GetRequiredService<IEnumerable<IPrinter>>().Count()));

Assert.That(
msContainer.GetRequiredService<IEnumerable<IPrinter>>().Count(),
Is.EqualTo(4));
}

private interface IPrinter { }

private class Printer : IPrinter { }

private class PrinterA : IPrinter { }

private class PrinterB : IPrinter { }

private class NeighborPrinter : IPrinter { }
}
}

0 comments on commit 45a60f4

Please sign in to comment.