mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Print autowirings in debug mode
This commit is contained in:
parent
666df9422b
commit
6b82c35b2e
|
@ -9,12 +9,23 @@ module poodinis.autowire;
|
||||||
|
|
||||||
public import poodinis.container;
|
public import poodinis.container;
|
||||||
|
|
||||||
|
debug {
|
||||||
|
import std.stdio;
|
||||||
|
import std.string;
|
||||||
|
}
|
||||||
|
|
||||||
class Autowire{};
|
class Autowire{};
|
||||||
|
|
||||||
public void autowire(Type)(Container container, Type instance) {
|
public void autowire(Type)(Container container, Type instance) {
|
||||||
foreach (member ; __traits(derivedMembers, Type)) {
|
foreach (member ; __traits(derivedMembers, Type)) {
|
||||||
foreach (attribute; mixin(`__traits(getAttributes, Type.` ~ member ~ `)`) ) {
|
foreach (attribute; mixin(`__traits(getAttributes, Type.` ~ member ~ `)`) ) {
|
||||||
if (is(attribute : Autowire) && __traits(getMember, instance, member) is null){
|
if (is(attribute : Autowire) && __traits(getMember, instance, member) is null){
|
||||||
|
debug {
|
||||||
|
auto autoWireType = typeid(typeof(__traits(getMember, instance, member)));
|
||||||
|
auto memberQualifier = typeid(Type).toString();
|
||||||
|
writeln(format("Autowire %s to %s.%s", autoWireType, memberQualifier, member));
|
||||||
|
}
|
||||||
|
|
||||||
__traits(getMember, instance, member) = container.resolve!(typeof(__traits(getMember, instance, member)));
|
__traits(getMember, instance, member) = container.resolve!(typeof(__traits(getMember, instance, member)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue