feat: Add DI container framework + core test infrastructure#1631
feat: Add DI container framework + core test infrastructure#1631bthebladeprimer wants to merge 3 commits into
Conversation
Generated by 🚫 Danger Swift against 01baa63 |
| /// | ||
| /// - Warning: The semaphore-based fallback blocks the calling thread while | ||
| /// waiting for actor-isolated async work. If called from the Swift | ||
| /// cooperative thread pool (e.g. inside a `Task`) this can deadlock |
There was a problem hiding this comment.
Can we do any better here, is there a way to not have this deadlock risk, or add a runtime assertion so it is unreachable from async contexts?
| if let stored = await container.getInstance(forKey: key) { | ||
| return stored | ||
| } | ||
| await container.setInstance(new, forKey: key) |
There was a problem hiding this comment.
We fetch stored twice here, but it is not clear from the code flow where or how stored is used. Is this relying on a side-effect?
There was a problem hiding this comment.
These PR review findings should not ship with the PR
| // MARK: - Diagnostics | ||
|
|
||
| /// Get diagnostic information about the container state | ||
| public func getDiagnostics() -> ContainerDiagnostics { |
There was a problem hiding this comment.
Does this need to be public? Not sure how useful this information would be to a merchant.
| // Copyright © 2026 Primer API Ltd. All rights reserved. | ||
| // Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
|
|
||
| // TODO: Rename file to DIContainer+SwiftUI.swift |
There was a problem hiding this comment.
Should we rename this file now?
| name: String? = nil | ||
| ) async throws -> Self { | ||
| let builder = register(F.self) | ||
| let namedBuilder = name != nil ? builder.named(name!) : builder |
There was a problem hiding this comment.
if let name instead of name!?
There was a problem hiding this comment.
I think you could also do name.map(builder.named) ?? builder
Add custom actor-based dependency injection framework with support for transient, singleton, and weak retention policies. Includes async/await resolution, SwiftUI environment integration, container diagnostics, and health checks. Ships with core test utilities (XCTestCase+Async, ContainerTestHelpers, TestData) and comprehensive DI test suite.
637b7c4 to
01baa63
Compare
Summary
XCTestCase+Async(async stream helpers),ContainerTestHelpers,TestDatabaseContext
This is PR 2 of 15 in the CheckoutComponents PR split. The DI framework is the foundation — all CheckoutComponents code resolves dependencies through this container.
Depends on: PR 1 (Build Config) — #1630
Tracking: Notion PR Review Tracker
Key files
Internal/DI/Framework/Container.swift— Core container implementation (actor-based)Internal/DI/Framework/DIContainer.swift— Singleton managing container lifecycleInternal/DI/Framework/Factory.swift— Factory pattern for parameterized creationInternal/DI/Framework/RetentionStrategy.swift— Memory management policiesTestSupport/XCTestCase+Async.swift— Async stream testing utilitiesTest plan
xcodebuild test -only-testing:"Tests/DIContainerTests"