-
-
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.
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...DryIoc.IssuesTests/GHIssue667_Resolve_with_serviceKey_does_not_invoke_factory_selector.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,45 @@ | ||
using NUnit.Framework; | ||
|
||
using System; | ||
using System.Text; | ||
using DryIoc.FastExpressionCompiler.LightExpression; | ||
using System.Linq; | ||
using System.Diagnostics; | ||
using DryIoc.ImTools; | ||
|
||
namespace DryIoc.IssuesTests; | ||
|
||
[TestFixture] | ||
public class GHIssue667_Resolve_with_serviceKey_does_not_invoke_factory_selector : ITest | ||
{ | ||
public int Run() | ||
{ | ||
// Original_case(); //todo: @fixme @wip | ||
return 1; | ||
} | ||
|
||
public interface IFoo { } | ||
public class Foo : IFoo { } | ||
|
||
[Test] | ||
public void Original_case() | ||
{ | ||
var count = 0; | ||
var container = new Container(rules => | ||
rules.WithFactorySelector( | ||
(request, single, many) => | ||
{ | ||
++count; | ||
return single | ||
?? many.FindFirst(request.ServiceKey, static (sk, f) => f.Key.Equals(sk))?.Value; | ||
})); | ||
|
||
container.Register<IFoo, Foo>(); // Default | ||
container.Register<IFoo, Foo>(serviceKey: "my"); // Keyed | ||
_ = container.Resolve<IFoo>(); // Custom factory selector invoked | ||
Assert.AreEqual(1, count); | ||
|
||
_ = container.Resolve<IFoo>("my"); // Custom factory selector NOT invoked | ||
Assert.AreEqual(2, count); | ||
} | ||
} |
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