-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...ts/GHIssue643_WithConcreteTypeDynamicRegistrations_results_in_unintended_instantiation.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,68 @@ | ||
using NUnit.Framework; | ||
using NUnit.Framework.Internal; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace DryIoc.IssuesTests; | ||
|
||
[TestFixture] | ||
public sealed class GHIssue643_WithConcreteTypeDynamicRegistrations_results_in_unintended_instantiation : ITest | ||
{ | ||
public int Run() | ||
{ | ||
Test_1(); | ||
Test_2(); | ||
Test_3(); | ||
return 3; | ||
} | ||
|
||
[Test] | ||
public void Test_1() | ||
{ | ||
var rules = Rules.Default.WithAutoConcreteTypeResolution(); | ||
|
||
var container = new Container(rules); | ||
container.Register<MyRegistry>(); | ||
|
||
var registry = container.Resolve<MyRegistry>(); | ||
Assert.IsEmpty(registry.Things); | ||
} | ||
|
||
[Test] | ||
public void Test_2() | ||
{ | ||
var rules = Rules.Default.WithConcreteTypeDynamicRegistrations(); | ||
|
||
var container = new Container(rules); | ||
container.Register<MyRegistry>(); | ||
|
||
var registry = container.Resolve<MyRegistry>(); | ||
// Assert.IsEmpty(registry.Things); // todo: @wip | ||
} | ||
|
||
[Test] | ||
public void Test_3() | ||
{ | ||
var rules = Rules.Default; | ||
|
||
var container = new Container(rules); | ||
container.Register<Thing>(); | ||
container.Register<MyRegistry>(); | ||
|
||
var registry = container.Resolve<MyRegistry>(); | ||
Assert.AreEqual(1, registry.Things.ToArray().Length); | ||
} | ||
|
||
public class MyRegistry | ||
{ | ||
public readonly IEnumerable<Thing> Things; | ||
public MyRegistry(IEnumerable<Thing> things) => Things = things; | ||
} | ||
|
||
public class Thing | ||
{ | ||
public Guid Id { get; set; } | ||
} | ||
} |
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