Skip to content

Commit

Permalink
Fixes #23 Local inject now correctly provides container to local modu…
Browse files Browse the repository at this point in the history
…le (#27)
  • Loading branch information
ncipollo authored Dec 12, 2024
1 parent 6a98e09 commit ce3bb94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions Sources/WhoopDIKit/Container/Container.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public final class Container {
}

let localModule = DependencyModule()
localModule.container = self
localDefinition(localModule)
localModule.addToServiceDictionary(serviceDict: localServiceDict)

Expand Down
16 changes: 15 additions & 1 deletion Tests/WhoopDIKitTests/Container/ContainerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()])
Expand Down

0 comments on commit ce3bb94

Please sign in to comment.