Add test for autowiring circular dependencies

This commit is contained in:
Mike Bierlee 2014-05-30 01:19:51 +02:00
parent f4ad79003e
commit 60b1149aea

View file

@ -26,6 +26,16 @@ version(unittest) {
public AutowiredClass autowiredClass; public AutowiredClass autowiredClass;
} }
class ComponentCat {
@Autowire
public ComponentMouse mouse;
}
class ComponentMouse {
@Autowire
public ComponentMouse cat;
}
// Test register concrete type // Test register concrete type
unittest { unittest {
auto container = new Container(); auto container = new Container();
@ -139,4 +149,13 @@ version(unittest) {
assert(componentInstance.autowiredClass is autowiredInstance, "Member is not autowired upon resolving"); assert(componentInstance.autowiredClass is autowiredInstance, "Member is not autowired upon resolving");
} }
// Test circular autowiring
unittest {
auto container = new Container();
container.register!ComponentMouse;
container.register!ComponentCat;
auto mouse = container.resolve!ComponentMouse;
auto cat = container.resolve!ComponentCat;
assert(mouse.cat is cat && cat.mouse is mouse, "Circular dependencies should be autowirable");
}
} }