Test that you can autowire members declared as an interface type

This commit is contained in:
Mike Bierlee 2014-05-27 02:02:07 +02:00
parent a9e5b315e3
commit 4957b67b49

View file

@ -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");
}
}