Skip to content

Commit 4d2a5d3

Browse files
committed
added failing test for #667
1 parent a07c730 commit 4d2a5d3

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using NUnit.Framework;
2+
3+
using System;
4+
using System.Text;
5+
using DryIoc.FastExpressionCompiler.LightExpression;
6+
using System.Linq;
7+
using System.Diagnostics;
8+
using DryIoc.ImTools;
9+
10+
namespace DryIoc.IssuesTests;
11+
12+
[TestFixture]
13+
public class GHIssue667_Resolve_with_serviceKey_does_not_invoke_factory_selector : ITest
14+
{
15+
public int Run()
16+
{
17+
// Original_case(); //todo: @fixme @wip
18+
return 1;
19+
}
20+
21+
public interface IFoo { }
22+
public class Foo : IFoo { }
23+
24+
[Test]
25+
public void Original_case()
26+
{
27+
var count = 0;
28+
var container = new Container(rules =>
29+
rules.WithFactorySelector(
30+
(request, single, many) =>
31+
{
32+
++count;
33+
return single
34+
?? many.FindFirst(request.ServiceKey, static (sk, f) => f.Key.Equals(sk))?.Value;
35+
}));
36+
37+
container.Register<IFoo, Foo>(); // Default
38+
container.Register<IFoo, Foo>(serviceKey: "my"); // Keyed
39+
_ = container.Resolve<IFoo>(); // Custom factory selector invoked
40+
Assert.AreEqual(1, count);
41+
42+
_ = container.Resolve<IFoo>("my"); // Custom factory selector NOT invoked
43+
Assert.AreEqual(2, count);
44+
}
45+
}

test/DryIoc.TestRunner/Program.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public class Program
99
{
1010
public static void Main()
1111
{
12-
new GHIssue503_Compile_time_container().Run();
12+
new GHIssue667_Resolve_with_serviceKey_does_not_invoke_factory_selector().Run();
13+
// new GHIssue503_Compile_time_container().Run();
1314
// new GHIssue659_Can_I_inspect_a_scope_for_all_the_dependencies_resolved_in_the_scope().Run();
1415
// new GHIssue191_Optional_IResolverContext_argument_in_Func_of_service().Run();
1516
// new GHIssue619_FaultySingletonDependency().Run();

0 commit comments

Comments
 (0)