-
-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #575 from Amleto/gh-issue-574
Add failing test for Gh issue #574
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
.../GHIssue574_Cannot_register_multiple_impls_in_child_container_with_default_service_key.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { } | ||
} | ||
} |