Fix template class injection

This commit is contained in:
Johannes Loher 2017-08-13 17:18:04 +02:00
parent ea940617b6
commit 233938faa8
2 changed files with 27 additions and 2 deletions

View file

@ -23,6 +23,8 @@ import poodinis.factory;
import poodinis.valueinjection; import poodinis.valueinjection;
import poodinis.polyfill; import poodinis.polyfill;
import std.algorithm;
import std.array;
import std.exception; import std.exception;
import std.stdio; import std.stdio;
import std.string; import std.string;
@ -262,10 +264,21 @@ class AutowiredRegistration(RegistrationType : Object) : Registration {
return instance; return instance;
} }
private static string[] createModuleList(Type)() {
string[] ret = [moduleName!Type];
static if (__traits(compiles, TemplateArgsOf!Type)) {
foreach (TemplateArg; TemplateArgsOf!Type) {
static if (!isBuiltinType!TemplateArg)
ret ~= createModuleList!TemplateArg;
}
}
return ret;
}
private void delegate() getPreDestructor(RegistrationType instance) { private void delegate() getPreDestructor(RegistrationType instance) {
void delegate() preDestructor = null; void delegate() preDestructor = null;
foreach (memberName; __traits(allMembers, RegistrationType)) { foreach (memberName; __traits(allMembers, RegistrationType)) {
mixin(`import ` ~ moduleName!RegistrationType ~ `;`); mixin(createModuleList!RegistrationType.map!(moduleName => `import ` ~ moduleName ~ `;`).join);
static if (__traits(compiles, __traits(getProtection, __traits(getMember, instance, memberName))) static if (__traits(compiles, __traits(getProtection, __traits(getMember, instance, memberName)))
&& __traits(getProtection, __traits(getMember, instance, memberName)) == "public" && __traits(getProtection, __traits(getMember, instance, memberName)) == "public"
&& isFunction!(mixin(fullyQualifiedName!RegistrationType ~ `.` ~ memberName)) && isFunction!(mixin(fullyQualifiedName!RegistrationType ~ `.` ~ memberName))

View file

@ -22,6 +22,7 @@ import poodinis.polyfill;
import std.string; import std.string;
import std.algorithm; import std.algorithm;
import std.array;
import std.concurrency; import std.concurrency;
import std.traits; import std.traits;
@ -389,9 +390,20 @@ synchronized class DependencyContainer {
return getRegistration(candidates, qualifierType); return getRegistration(candidates, qualifierType);
} }
private static string[] createModuleList(Type)() {
string[] ret = [moduleName!Type];
static if (__traits(compiles, TemplateArgsOf!Type)) {
foreach (TemplateArg; TemplateArgsOf!Type) {
static if (!isBuiltinType!TemplateArg)
ret ~= createModuleList!TemplateArg;
}
}
return ret;
}
private void callPostConstructors(Type)(Type instance) { private void callPostConstructors(Type)(Type instance) {
foreach (memberName; __traits(allMembers, Type)) { foreach (memberName; __traits(allMembers, Type)) {
mixin(`import ` ~ moduleName!Type ~ `;`); mixin(createModuleList!Type.map!(moduleName => `import ` ~ moduleName ~ `;`).join);
static if (__traits(compiles, __traits(getProtection, __traits(getMember, instance, memberName))) static if (__traits(compiles, __traits(getProtection, __traits(getMember, instance, memberName)))
&& __traits(getProtection, __traits(getMember, instance, memberName)) == "public" && __traits(getProtection, __traits(getMember, instance, memberName)) == "public"
&& isFunction!(mixin(fullyQualifiedName!Type ~ `.` ~ memberName)) && isFunction!(mixin(fullyQualifiedName!Type ~ `.` ~ memberName))