mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Merge pull request #24 from aruthane/fix-create-import-string-template-arg-recursion
Support recursive template arguments with createImportsString
This commit is contained in:
commit
f7a86702be
|
@ -11,14 +11,15 @@
|
||||||
|
|
||||||
module poodinis.imports;
|
module poodinis.imports;
|
||||||
|
|
||||||
|
import std.meta;
|
||||||
import std.traits;
|
import std.traits;
|
||||||
|
|
||||||
public static string createImportsString(Type)() {
|
public static string createImportsString(Type, ParentTypeList...)() {
|
||||||
string imports = `import ` ~ moduleName!Type ~ `;`;
|
string imports = `import ` ~ moduleName!Type ~ `;`;
|
||||||
static if (__traits(compiles, TemplateArgsOf!Type)) {
|
static if (__traits(compiles, TemplateArgsOf!Type)) {
|
||||||
foreach(TemplateArgType; TemplateArgsOf!Type) {
|
foreach(TemplateArgType; TemplateArgsOf!Type) {
|
||||||
static if (!isBuiltinType!TemplateArgType) {
|
static if (!isBuiltinType!TemplateArgType && staticIndexOf!(TemplateArgType, ParentTypeList) == -1) {
|
||||||
imports ~= createImportsString!TemplateArgType;
|
imports ~= createImportsString!(TemplateArgType, ParentTypeList, Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import poodinis;
|
||||||
import poodinis.test.testClasses;
|
import poodinis.test.testClasses;
|
||||||
|
|
||||||
import std.exception;
|
import std.exception;
|
||||||
|
import std.meta;
|
||||||
|
|
||||||
version(unittest) {
|
version(unittest) {
|
||||||
|
|
||||||
|
@ -179,4 +180,20 @@ version(unittest) {
|
||||||
assert(instance.intValue == 8);
|
assert(instance.intValue == 8);
|
||||||
assert(instance.unrelated !is null);
|
assert(instance.unrelated !is null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test autowiring classes with recursive template parameters
|
||||||
|
unittest {
|
||||||
|
auto container = new shared DependencyContainer();
|
||||||
|
container.register!CircularTemplateComponentA;
|
||||||
|
container.register!CircularTemplateComponentB;
|
||||||
|
|
||||||
|
auto componentA = container.resolve!CircularTemplateComponentA;
|
||||||
|
auto componentB = container.resolve!CircularTemplateComponentB;
|
||||||
|
|
||||||
|
assert(componentA !is null);
|
||||||
|
assert(componentB !is null);
|
||||||
|
|
||||||
|
assert(componentA.instance is componentB);
|
||||||
|
assert(componentB.instance is componentA);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -630,4 +630,17 @@ version(unittest) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TemplatedComponent(T) {
|
||||||
|
@Autowire
|
||||||
|
T instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CircularTemplateComponentA : TemplatedComponent!CircularTemplateComponentB {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class CircularTemplateComponentB : TemplatedComponent!CircularTemplateComponentA {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue