diff --git a/source/poodinis/autowire.d b/source/poodinis/autowire.d index 4c0e673..8131a75 100644 --- a/source/poodinis/autowire.d +++ b/source/poodinis/autowire.d @@ -23,6 +23,8 @@ import poodinis.factory; import poodinis.valueinjection; import poodinis.polyfill; +import std.algorithm; +import std.array; import std.exception; import std.stdio; import std.string; @@ -262,10 +264,21 @@ class AutowiredRegistration(RegistrationType : Object) : Registration { 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) { void delegate() preDestructor = null; 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))) && __traits(getProtection, __traits(getMember, instance, memberName)) == "public" && isFunction!(mixin(fullyQualifiedName!RegistrationType ~ `.` ~ memberName)) diff --git a/source/poodinis/container.d b/source/poodinis/container.d index 6c58f4b..bc880e7 100644 --- a/source/poodinis/container.d +++ b/source/poodinis/container.d @@ -22,6 +22,7 @@ import poodinis.polyfill; import std.string; import std.algorithm; +import std.array; import std.concurrency; import std.traits; @@ -389,9 +390,20 @@ synchronized class DependencyContainer { 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) { 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))) && __traits(getProtection, __traits(getMember, instance, memberName)) == "public" && isFunction!(mixin(fullyQualifiedName!Type ~ `.` ~ memberName))