Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #23 Local inject now correctly provides container to local module #27

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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