mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Test that you can autowire members declared as an interface type
This commit is contained in:
parent
a9e5b315e3
commit
4957b67b49
|
@ -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");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue