Determine qualifier earlier in process

This commit is contained in:
Mike Bierlee 2016-12-06 23:41:08 +01:00
parent ee35b07a87
commit ea41a04657

View file

@ -128,14 +128,14 @@ private void printDebugAutowiringArray(TypeInfo superTypeInfo, TypeInfo instance
private void autowireMember(string member, size_t memberIndex, Type)(shared(DependencyContainer) container, Type instance) { private void autowireMember(string member, size_t memberIndex, Type)(shared(DependencyContainer) container, Type instance) {
foreach(attribute; __traits(getAttributes, Type.tupleof[memberIndex])) { foreach(attribute; __traits(getAttributes, Type.tupleof[memberIndex])) {
static if (is(attribute == Autowire!T, T)) { static if (is(attribute == Autowire!T, T)) {
injectInstance!(member, memberIndex, attribute)(container, instance); injectInstance!(member, memberIndex, typeof(attribute.qualifier))(container, instance);
} else if (__traits(isSame, attribute, Autowire)) { } else if (__traits(isSame, attribute, Autowire)) {
injectInstance!(member, memberIndex, Autowire!UseMemberType)(container, instance); injectInstance!(member, memberIndex, UseMemberType)(container, instance);
} }
} }
} }
private void injectInstance(string member, size_t memberIndex, autowireAttribute, Type)(shared(DependencyContainer) container, Type instance) { private void injectInstance(string member, size_t memberIndex, QualifierType, Type)(shared(DependencyContainer) container, Type instance) {
if (instance.tupleof[memberIndex] is null) { if (instance.tupleof[memberIndex] is null) {
alias MemberType = typeof(Type.tupleof[memberIndex]); alias MemberType = typeof(Type.tupleof[memberIndex]);
enum isOptional = hasUDA!(Type.tupleof[memberIndex], OptionalDependency); enum isOptional = hasUDA!(Type.tupleof[memberIndex], OptionalDependency);
@ -143,7 +143,7 @@ private void injectInstance(string member, size_t memberIndex, autowireAttribute
static if (isDynamicArray!MemberType) { static if (isDynamicArray!MemberType) {
injectMultipleInstances!(member, memberIndex, isOptional, MemberType)(container, instance); injectMultipleInstances!(member, memberIndex, isOptional, MemberType)(container, instance);
} else { } else {
injectSingleInstance!(member, memberIndex, autowireAttribute, isOptional, MemberType)(container, instance); injectSingleInstance!(member, memberIndex, isOptional, MemberType, QualifierType)(container, instance);
} }
} }
} }
@ -162,7 +162,7 @@ private void injectMultipleInstances(string member, size_t memberIndex, bool isO
} }
} }
private void injectSingleInstance(string member, size_t memberIndex, autowireAttribute, bool isOptional, MemberType, Type)(shared(DependencyContainer) container, Type instance) { private void injectSingleInstance(string member, size_t memberIndex, bool isOptional, MemberType, QualifierType, Type)(shared(DependencyContainer) container, Type instance) {
debug(poodinisVerbose) { debug(poodinisVerbose) {
TypeInfo qualifiedInstanceType = typeid(MemberType); TypeInfo qualifiedInstanceType = typeid(MemberType);
} }
@ -170,8 +170,7 @@ private void injectSingleInstance(string member, size_t memberIndex, autowireAtt
enum assignNewInstance = hasUDA!(Type.tupleof[memberIndex], AssignNewInstance); enum assignNewInstance = hasUDA!(Type.tupleof[memberIndex], AssignNewInstance);
MemberType qualifiedInstance; MemberType qualifiedInstance;
static if (is(autowireAttribute == Autowire!T, T) && !is(typeof(autowireAttribute.qualifier) == UseMemberType)) { static if (!is(QualifierType == UseMemberType)) {
alias QualifierType = typeof(autowireAttribute.qualifier);
qualifiedInstance = createOrResolveInstance!(MemberType, QualifierType, assignNewInstance, isOptional)(container); qualifiedInstance = createOrResolveInstance!(MemberType, QualifierType, assignNewInstance, isOptional)(container);
debug(poodinisVerbose) { debug(poodinisVerbose) {
qualifiedInstanceType = typeid(QualifierType); qualifiedInstanceType = typeid(QualifierType);