mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add test for resolve by interface workaround
This commit is contained in:
parent
17c833a114
commit
47d7f72fae
|
@ -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");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue