Add registeration of context components when registering via dependency container

This commit is contained in:
Mike Bierlee 2015-12-24 20:12:35 +01:00
parent 57b548aeae
commit 2e4c688ab2
2 changed files with 15 additions and 0 deletions

View file

@ -372,6 +372,7 @@ synchronized class DependencyContainer {
public void registerContext(Context : ApplicationContext)() { public void registerContext(Context : ApplicationContext)() {
auto context = new Context(); auto context = new Context();
context.registerDependencies(this); context.registerDependencies(this);
context.registerContextComponents(this);
} }
/** /**

View file

@ -15,6 +15,11 @@ version(unittest) {
public override void registerDependencies(shared(DependencyContainer) container) { public override void registerDependencies(shared(DependencyContainer) container) {
container.register!TestClass; container.register!TestClass;
} }
@Component
public UnrelatedClass unrelated() {
return new UnrelatedClass();
}
} }
interface TestInterface { interface TestInterface {
@ -500,4 +505,13 @@ version(unittest) {
assert(instance !is null); assert(instance !is null);
} }
// Test resolving dependency from registered application context
unittest {
shared(DependencyContainer) container = new DependencyContainer();
container.registerContext!TestContext;
auto instance = container.resolve!UnrelatedClass;
assert(instance !is null);
}
} }