Add test that asserts whether autowiring a class that depends on itself works.

This commit is contained in:
Mike Bierlee 2015-02-23 20:01:44 +01:00
parent 89d82efb11
commit 83ad8c64c0

View file

@ -95,6 +95,11 @@ version(unittest) {
public TestInterface testMember; public TestInterface testMember;
} }
class Recursive {
@Autowire
public Recursive recursive;
}
// Test register concrete type // Test register concrete type
unittest { unittest {
auto container = new DependencyContainer(); auto container = new DependencyContainer();
@ -353,4 +358,15 @@ version(unittest) {
assert(firstRegistration is secondRegistration, "Registering the same registration by super type twice registers the dependencies twice."); assert(firstRegistration is secondRegistration, "Registering the same registration by super type twice registers the dependencies twice.");
} }
// Resolve dependency depending on itself
unittest {
auto container = new DependencyContainer();
container.register!Recursive;
auto instance = container.resolve!Recursive;
assert(instance.recursive is instance, "Resolving dependency that depends on itself fails.");
assert(instance.recursive.recursive is instance, "Resolving dependency that depends on itself fails.");
}
} }