mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
parent
91fcefa7ed
commit
93d4d3c20f
|
@ -22,6 +22,7 @@ import poodinis.registration;
|
||||||
import poodinis.factory;
|
import poodinis.factory;
|
||||||
import poodinis.valueinjection;
|
import poodinis.valueinjection;
|
||||||
import poodinis.polyfill;
|
import poodinis.polyfill;
|
||||||
|
import poodinis.imports;
|
||||||
|
|
||||||
import std.exception;
|
import std.exception;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
@ -265,7 +266,7 @@ class AutowiredRegistration(RegistrationType : Object) : Registration {
|
||||||
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(createImportsString!RegistrationType);
|
||||||
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))
|
||||||
|
|
|
@ -19,6 +19,7 @@ import poodinis.context;
|
||||||
import poodinis.factory;
|
import poodinis.factory;
|
||||||
import poodinis.valueinjection;
|
import poodinis.valueinjection;
|
||||||
import poodinis.polyfill;
|
import poodinis.polyfill;
|
||||||
|
import poodinis.imports;
|
||||||
|
|
||||||
import std.string;
|
import std.string;
|
||||||
import std.algorithm;
|
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.
|
* Clears all dependency registrations managed by this container.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
module poodinis.factory;
|
module poodinis.factory;
|
||||||
|
|
||||||
import poodinis.container;
|
import poodinis.container;
|
||||||
|
import poodinis.imports;
|
||||||
|
|
||||||
import std.typecons;
|
import std.typecons;
|
||||||
import std.exception;
|
import std.exception;
|
||||||
|
@ -122,7 +123,7 @@ class ConstructorInjectingInstanceFactory(InstanceType) : InstanceFactory {
|
||||||
private static string createImportList(Params...)() {
|
private static string createImportList(Params...)() {
|
||||||
string importList = "";
|
string importList = "";
|
||||||
foreach(param; Params) {
|
foreach(param; Params) {
|
||||||
importList ~= "import " ~ moduleName!param ~ ";";
|
importList ~= createImportsString!param;
|
||||||
}
|
}
|
||||||
return importList;
|
return importList;
|
||||||
}
|
}
|
||||||
|
@ -148,9 +149,8 @@ class ConstructorInjectingInstanceFactory(InstanceType) : InstanceFactory {
|
||||||
foreach(ctor ; __traits(getOverloads, InstanceType, `__ctor`)) {
|
foreach(ctor ; __traits(getOverloads, InstanceType, `__ctor`)) {
|
||||||
static if (parametersAreValid!(Parameters!ctor)) {
|
static if (parametersAreValid!(Parameters!ctor)) {
|
||||||
isBeingInjected = true;
|
isBeingInjected = true;
|
||||||
mixin(`
|
mixin(createImportsString!InstanceType
|
||||||
import ` ~ moduleName!InstanceType ~ `;
|
~ createImportList!(Parameters!ctor) ~ `
|
||||||
` ~ createImportList!(Parameters!ctor) ~ `
|
|
||||||
instance = new ` ~ fullyQualifiedName!InstanceType ~ `(` ~ createArgumentList!(Parameters!ctor) ~ `);
|
instance = new ` ~ fullyQualifiedName!InstanceType ~ `(` ~ createArgumentList!(Parameters!ctor) ~ `);
|
||||||
`);
|
`);
|
||||||
isBeingInjected = false;
|
isBeingInjected = false;
|
||||||
|
|
16
source/poodinis/imports.d
Normal file
16
source/poodinis/imports.d
Normal file
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in a new issue