From ce3bb94e7b553ab72daf422699f79272b37fab87 Mon Sep 17 00:00:00 2001 From: Nick Cipollo Date: Thu, 12 Dec 2024 09:23:06 -0500 Subject: [PATCH] Fixes #23 Local inject now correctly provides container to local module (#27) --- Sources/WhoopDIKit/Container/Container.swift | 1 + .../Container/ContainerTests.swift | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Sources/WhoopDIKit/Container/Container.swift b/Sources/WhoopDIKit/Container/Container.swift index 10dfbcc..f096a60 100644 --- a/Sources/WhoopDIKit/Container/Container.swift +++ b/Sources/WhoopDIKit/Container/Container.swift @@ -73,6 +73,7 @@ public final class Container { } let localModule = DependencyModule() + localModule.container = self localDefinition(localModule) localModule.addToServiceDictionary(serviceDict: localServiceDict) diff --git a/Tests/WhoopDIKitTests/Container/ContainerTests.swift b/Tests/WhoopDIKitTests/Container/ContainerTests.swift index 0a8e2d9..e3fee37 100644 --- a/Tests/WhoopDIKitTests/Container/ContainerTests.swift +++ b/Tests/WhoopDIKitTests/Container/ContainerTests.swift @@ -41,7 +41,21 @@ class ContainerTests: @unchecked Sendable { } #expect(dependency is DependencyA) } - + + @Test(.bug("https://github.com/WhoopInc/WhoopDI/issues/23")) + func inject_localDefinition_dependenciesWithinLocalModule() { + container.registerModules(modules: [BadTestModule()]) + let dependency: Dependency = container.inject("C_Factory", params: "params") { module in + module.factoryWithParams(name: "C_Factory") { params in + DependencyC(proto: try module.get("A_Factory"), + concrete: try module.get(params: params)) as Dependency + } + module.factory(name: "A_Factory") { DependencyA() as Dependency } + module.factoryWithParams { params in DependencyB(params) } + } + #expect(dependency is DependencyC) + } + @Test(.bug("https://github.com/WhoopInc/WhoopDI/issues/13")) func inject_localDefinition_concurrency() async { container.registerModules(modules: [GoodTestModule()])