From f97a689f2912ca6c87403a65414bc4312390488c Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Fri, 13 Jun 2014 23:49:34 +0200 Subject: [PATCH] Accept defeat and recognize resolve by supertype/interface bug For now.... --- README.md | 5 +++-- test/poodinis/containertest.d | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 85a35c8..ef080bc 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ assert(exampleInstance.dependency !is null); ``` At the moment, it is only possible to autowire public members or properties. -Dependencies are automatically autowired when a class is resolved. So when you register ExampleClassB, its member, *dependency*, is automatically injected: +Dependencies are automatically autowired when a class is resolved. So when you register ExampleClassB, its member, *dependency*, is automatically autowired: ```d container.register!ExampleClassA; container.register!ExampleClassB; @@ -121,7 +121,8 @@ Poodinis can autowire circular dependencies when they are registered with single Known issues ------------ -* Due to preventive measures of recursion issues in circular dependencies, registrations which are supposed to yield new instances will not autowire classes for which a circular dependency is detected. A new instance will be resolved but the instance's members will not be autowired. +* Due to preventive measures of recursion issues in circular dependencies, registrations which are supposed to yield new instances will not autowire classes for which a circular dependency is detected. A new instance will be resolved but the instance's members will not be autowired. +* Resolving a class registered by supertype or interface will only autowire the members inherited from its supertype and in the case of interfaces nothing at all. Future Work ----------- diff --git a/test/poodinis/containertest.d b/test/poodinis/containertest.d index f833f4c..6a3edfc 100644 --- a/test/poodinis/containertest.d +++ b/test/poodinis/containertest.d @@ -73,6 +73,14 @@ version(unittest) { public Bittie bittie; } + interface SuperInterface { + } + + class SuperImplementation : SuperInterface { + @Autowire + public Banana banana; + } + // Test register concrete type unittest { auto container = new Container(); @@ -224,4 +232,15 @@ version(unittest) { assert(ittie.bittie.banana.bittie.banana is null, "Autowiring deep dependencies with newInstance scope autowired a reoccuring type."); } + + // Test autowiring type registered by interface + unittest { + auto container = new Container(); + container.register!Banana; + container.register!(SuperInterface, SuperImplementation); + + SuperImplementation superInstance = cast(SuperImplementation) container.resolve!SuperInterface; + + assert(superInstance.banana is null, "Autowire instance which was resolved by interface type, which was not expected to be possible"); + } } \ No newline at end of file