From 47d7f72fae90fa834541bc2d2b75b9576c3f7f43 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Sun, 22 Jun 2014 16:33:15 +0200 Subject: [PATCH] Add test for resolve by interface workaround --- test/poodinis/autowiretest.d | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/poodinis/autowiretest.d b/test/poodinis/autowiretest.d index 37fed0c..e7f23fa 100644 --- a/test/poodinis/autowiretest.d +++ b/test/poodinis/autowiretest.d @@ -42,6 +42,16 @@ version(unittest) { public ComponentC componentC; } + class ComponentF { + @Autowire + public ComponentA componentA; + + public this() { + auto container = Container.getInstance(); + container.autowire!ComponentF(this); + } + } + // Test autowiring concrete type to existing instance unittest { auto container = new Container(); @@ -86,4 +96,17 @@ version(unittest) { container.autowire!ComponentE(componentE); assert(componentE.componentC is null, "Autowiring should not occur for members with attributes other than @Autowire"); } + + // Test autowire in constructor + unittest { + auto container = Container.getInstance(); + container.register!ComponentA; + auto componentF = new ComponentF(); + auto autowiredComponentA = componentF.componentA; + container.register!(ComponentF).existingInstance(componentF); + assert(componentF.componentA !is null, "Constructor did not autowire component F"); + + auto resolvedComponentF = container.resolve!ComponentF; + assert(resolvedComponentF.componentA is autowiredComponentA, "Resolving instance of ComponentF rewired members"); + } } \ No newline at end of file