Skip to content

Commit f885587

Browse files
committed
added the test for the #387
1 parent f0db87f commit f885587

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using NUnit.Framework;
2+
3+
namespace DryIoc.IssuesTests
4+
{
5+
[TestFixture]
6+
public class GHIssue387_Nested_container_returns_a_new_instance_for_singletons
7+
{
8+
[Test]
9+
public void Test1()
10+
{
11+
var c = new Container(Rules.MicrosoftDependencyInjectionRules);
12+
13+
c.Register<IMemoryCache, MemCache>(Reuse.Singleton);
14+
15+
IMemoryCache cache1 = null;
16+
17+
// cache1 = c.Resolve<IMemoryCache>();
18+
19+
using (var nested = c.CreateChild())
20+
{
21+
using (var scope = nested.OpenScope())
22+
{
23+
cache1 = scope.Resolve<IMemoryCache>();
24+
var cache2 = scope.Resolve<IMemoryCache>();
25+
26+
Assert.AreSame(cache2, cache1);
27+
}
28+
29+
var cache3 = nested.Resolve<IMemoryCache>();
30+
Assert.AreSame(cache3, cache1);
31+
}
32+
33+
// Uncomment the line above for this assert to pass.
34+
// var cache4 = c.Resolve<IMemoryCache>();
35+
// Assert.AreSame(cache4, cache1);
36+
}
37+
38+
interface IMemoryCache {}
39+
class MemCache : IMemoryCache {}
40+
}
41+
}

0 commit comments

Comments
 (0)