From 83ad8c64c01dda472313dc1d0a543108477e2aa5 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Mon, 23 Feb 2015 20:01:44 +0100 Subject: [PATCH] Add test that asserts whether autowiring a class that depends on itself works. --- test/poodinis/containertest.d | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/poodinis/containertest.d b/test/poodinis/containertest.d index 8c7b966..0881782 100644 --- a/test/poodinis/containertest.d +++ b/test/poodinis/containertest.d @@ -95,6 +95,11 @@ version(unittest) { public TestInterface testMember; } + class Recursive { + @Autowire + public Recursive recursive; + } + // Test register concrete type unittest { auto container = new DependencyContainer(); @@ -353,4 +358,15 @@ version(unittest) { assert(firstRegistration is secondRegistration, "Registering the same registration by super type twice registers the dependencies twice."); } + + // Resolve dependency depending on itself + unittest { + auto container = new DependencyContainer(); + container.register!Recursive; + + auto instance = container.resolve!Recursive; + + assert(instance.recursive is instance, "Resolving dependency that depends on itself fails."); + assert(instance.recursive.recursive is instance, "Resolving dependency that depends on itself fails."); + } }