diff --git a/source/poodinis/autowire.d b/source/poodinis/autowire.d index 4c0e673..e95e790 100644 --- a/source/poodinis/autowire.d +++ b/source/poodinis/autowire.d @@ -22,6 +22,7 @@ import poodinis.registration; import poodinis.factory; import poodinis.valueinjection; import poodinis.polyfill; +import poodinis.imports; import std.exception; import std.stdio; @@ -265,7 +266,7 @@ class AutowiredRegistration(RegistrationType : Object) : Registration { private void delegate() getPreDestructor(RegistrationType instance) { void delegate() preDestructor = null; foreach (memberName; __traits(allMembers, RegistrationType)) { - mixin(`import ` ~ moduleName!RegistrationType ~ `;`); + mixin(createImportsString!RegistrationType); 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 fa52536..86a7102 100644 --- a/source/poodinis/container.d +++ b/source/poodinis/container.d @@ -19,6 +19,7 @@ import poodinis.context; import poodinis.factory; import poodinis.valueinjection; import poodinis.polyfill; +import poodinis.imports; import std.string; import std.algorithm; @@ -402,19 +403,6 @@ synchronized class DependencyContainer { } } - private static string createImportsString(Type)() { - string imports = `import ` ~ moduleName!Type ~ `;`; - static if (__traits(compiles, TemplateArgsOf!Type)) { - foreach(TemplateArgType; TemplateArgsOf!Type) { - static if (!isBuiltinType!TemplateArgType) { - imports ~= createImportsString!TemplateArgType; - } - } - } - - return imports; - } - /** * Clears all dependency registrations managed by this container. */ diff --git a/source/poodinis/factory.d b/source/poodinis/factory.d index 048a27b..4103978 100644 --- a/source/poodinis/factory.d +++ b/source/poodinis/factory.d @@ -12,6 +12,7 @@ module poodinis.factory; import poodinis.container; +import poodinis.imports; import std.typecons; import std.exception; @@ -122,7 +123,7 @@ class ConstructorInjectingInstanceFactory(InstanceType) : InstanceFactory { private static string createImportList(Params...)() { string importList = ""; foreach(param; Params) { - importList ~= "import " ~ moduleName!param ~ ";"; + importList ~= createImportsString!param; } return importList; } @@ -148,9 +149,8 @@ class ConstructorInjectingInstanceFactory(InstanceType) : InstanceFactory { foreach(ctor ; __traits(getOverloads, InstanceType, `__ctor`)) { static if (parametersAreValid!(Parameters!ctor)) { isBeingInjected = true; - mixin(` - import ` ~ moduleName!InstanceType ~ `; - ` ~ createImportList!(Parameters!ctor) ~ ` + mixin(createImportsString!InstanceType + ~ createImportList!(Parameters!ctor) ~ ` instance = new ` ~ fullyQualifiedName!InstanceType ~ `(` ~ createArgumentList!(Parameters!ctor) ~ `); `); isBeingInjected = false; diff --git a/source/poodinis/imports.d b/source/poodinis/imports.d new file mode 100644 index 0000000..0e4a152 --- /dev/null +++ b/source/poodinis/imports.d @@ -0,0 +1,16 @@ +module poodinis.imports; + +import std.traits; + +public static string createImportsString(Type)() { + string imports = `import ` ~ moduleName!Type ~ `;`; + static if (__traits(compiles, TemplateArgsOf!Type)) { + foreach(TemplateArgType; TemplateArgsOf!Type) { + static if (!isBuiltinType!TemplateArgType) { + imports ~= createImportsString!TemplateArgType; + } + } + } + + return imports; +} \ No newline at end of file