mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Merge pull request #8 from Extrawurst/develop
fix autowiring in base classes
This commit is contained in:
commit
7e058170dc
|
@ -101,6 +101,12 @@ public void autowire(Type)(shared(DependencyContainer) container, Type instance)
|
||||||
printDebugAutowiredInstance(typeid(Type), &instance);
|
printDebugAutowiredInstance(typeid(Type), &instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// note: recurse into base class if there are more between Type and Object in the hirarchy
|
||||||
|
static if(BaseClassesTuple!Type.length > 1)
|
||||||
|
{
|
||||||
|
autowire!(BaseClassesTuple!Type[0])(container, instance);
|
||||||
|
}
|
||||||
|
|
||||||
foreach(idx, name; FieldNameTuple!Type) {
|
foreach(idx, name; FieldNameTuple!Type) {
|
||||||
autowireMember!(name, idx, Type)(container, instance);
|
autowireMember!(name, idx, Type)(container, instance);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,9 @@ version(unittest) {
|
||||||
|
|
||||||
class ComponentX : InterfaceA {}
|
class ComponentX : InterfaceA {}
|
||||||
|
|
||||||
|
class ComponentZ : ComponentB {
|
||||||
|
}
|
||||||
|
|
||||||
class MonkeyShine {
|
class MonkeyShine {
|
||||||
@Autowire!ComponentX
|
@Autowire!ComponentX
|
||||||
public InterfaceA component;
|
public InterfaceA component;
|
||||||
|
@ -198,4 +201,17 @@ version(unittest) {
|
||||||
|
|
||||||
assert(charlie.componentA !is regularComponentA, "Autowiring class with AssignNewInstance did not yield a different instance");
|
assert(charlie.componentA !is regularComponentA, "Autowiring class with AssignNewInstance did not yield a different instance");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test autowiring members from base class
|
||||||
|
unittest {
|
||||||
|
shared(DependencyContainer) container = new DependencyContainer();
|
||||||
|
container.register!ComponentA;
|
||||||
|
container.register!ComponentB;
|
||||||
|
container.register!ComponentZ;
|
||||||
|
|
||||||
|
auto instance = new ComponentZ();
|
||||||
|
container.autowire(instance);
|
||||||
|
|
||||||
|
assert(instance.componentA !is null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue