mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Extract autowiring a member from autowire
This commit is contained in:
parent
6fbb313743
commit
58073dd160
|
@ -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));
|
||||
}
|
||||
|
@ -121,7 +127,6 @@ public void autowire(Type)(DependencyContainer container, Type instance) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Autowire the given instance using the globally available dependency container.
|
||||
|
|
Loading…
Reference in a new issue