Extract autowiring a member from autowire

This commit is contained in:
Mike Bierlee 2015-02-28 15:51:57 +01:00
parent 6fbb313743
commit 58073dd160

View file

@ -77,8 +77,6 @@ struct Autowire(QualifierType = UseMemberType) {
* See_Also: Autowire
*/
public void autowire(Type)(DependencyContainer container, Type instance) {
// For the love of god, refactor this!
debug(poodinisVerbose) {
auto instanceType = typeid(Type);
auto instanceAddress = &instance;
@ -86,6 +84,12 @@ public void autowire(Type)(DependencyContainer container, Type instance) {
}
foreach (member ; __traits(allMembers, Type)) {
autowireMember!(member)(container, instance);
}
}
private void autowireMember(string member, Type)(DependencyContainer container, Type instance) {
// For the love of god, refactor this! <-- Doing it, bro!
static if(__traits(compiles, __traits(getMember, Type, member)) && __traits(compiles, __traits(getAttributes, __traits(getMember, Type, member)))) {
foreach(autowireAttribute; __traits(getAttributes, __traits(getMember, Type, member))) {
static if (__traits(isSame, autowireAttribute, Autowire) || is(autowireAttribute == Autowire!T, T)) {
@ -111,6 +115,8 @@ public void autowire(Type)(DependencyContainer container, Type instance) {
__traits(getMember, instance, member) = qualifiedInstance;
debug(poodinisVerbose) {
auto instanceType = typeid(Type);
auto instanceAddress = &instance;
auto qualifiedInstanceAddress = &qualifiedInstance;
writeln(format("DEBUG: Autowired instance [%s@%s] to [%s@%s].%s", qualifiedInstanceTypeString, qualifiedInstanceAddress, instanceType, instanceAddress, member));
}
@ -120,7 +126,6 @@ public void autowire(Type)(DependencyContainer container, Type instance) {
}
}
}
}
}
/**