From 2e4c688ab2447103159f1f1a21cf4978982d7583 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Thu, 24 Dec 2015 20:12:35 +0100 Subject: [PATCH] Add registeration of context components when registering via dependency container --- source/poodinis/container.d | 1 + test/poodinis/containertest.d | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/source/poodinis/container.d b/source/poodinis/container.d index 7ed61fa..d9fc746 100644 --- a/source/poodinis/container.d +++ b/source/poodinis/container.d @@ -372,6 +372,7 @@ synchronized class DependencyContainer { public void registerContext(Context : ApplicationContext)() { auto context = new Context(); context.registerDependencies(this); + context.registerContextComponents(this); } /** diff --git a/test/poodinis/containertest.d b/test/poodinis/containertest.d index da32df9..4c47098 100644 --- a/test/poodinis/containertest.d +++ b/test/poodinis/containertest.d @@ -15,6 +15,11 @@ version(unittest) { public override void registerDependencies(shared(DependencyContainer) container) { container.register!TestClass; } + + @Component + public UnrelatedClass unrelated() { + return new UnrelatedClass(); + } } interface TestInterface { @@ -500,4 +505,13 @@ version(unittest) { 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); + } }