diff --git a/test/poodinis/autowiretest.d b/test/poodinis/autowiretest.d index 59b444a..db78ad4 100644 --- a/test/poodinis/autowiretest.d +++ b/test/poodinis/autowiretest.d @@ -12,6 +12,20 @@ version(unittest) { } } + interface InterfaceA { + } + + class ComponentC : InterfaceA { + } + + class ComponentD { + public @Autowire InterfaceA componentC; + + public bool componentIsNull() { + return componentC is null; + } + } + // Test autowiring concrete type to existing instance unittest { auto container = new Container(); @@ -20,4 +34,13 @@ version(unittest) { container.autowire!(ComponentB)(componentB); assert(!componentB.componentIsNull(), "Autowirable dependency failed to autowire"); } + + // Test autowiring interface type to existing instance + unittest { + auto container = new Container(); + container.register!(InterfaceA, ComponentC); + ComponentD componentD = new ComponentD(); + container.autowire!(ComponentD)(componentD); + assert(!componentD.componentIsNull(), "Autowirable dependency failed to autowire"); + } } \ No newline at end of file