-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: Async init #19
base: develop
Are you sure you want to change the base?
feat: Async init #19
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I apologize for request changes, but I just wanna you double check the solution as well. There are many similarities in all those typealiases for "factories" but some of the types are not very understandable - although it's async copy paste of existing.
I know we're adding new "feature" without breaking changes, at the same time we created async DI for exploring swift6 complete concurrency check really fast way, therefore I'm for double check.
Package.swift
Outdated
@@ -1,4 +1,4 @@ | |||
// swift-tools-version:5.5 | |||
// swift-tools-version:5.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't we have 5.9?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed 👍
let factory: AsyncRegistrationFactory | ||
|
||
/// Initializer for registrations that don't need any variable argument | ||
init<T: Sendable>(type: T.Type, scope: DependencyScope, factory: @Sendable @escaping (any AsyncDependencyResolving) async -> T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
factory parameter I found a bit confusing because when initializing AsyncRegistration in AsyncContainer we pass argument of type Factory defined in AsyncDependencyRegistering, not sure if we can optimize those typealiases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied the naming as it was in sync implementation, it did make sense to me. I will revisit it 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, as I look into it, it kinda makes sense, because AsyncDependencyResolving
has different factory then AsyncRegistration
, due to the fact that there is an optional parameter in AsyncRegistrationFactory
. I would keep it as it is, since nothing better comes to my mind at the moment 😄
I only changed property name, so it's not confusing and we can now distinguish between asyncRegistrationFactory
and factory
parameter 😄
…ependency-injection into feat/rob-async-init
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very handy! I have just a few documentation and tests comments.
private var registrations = [RegistrationIdentifier: AsyncRegistration]() | ||
private var sharedInstances = [RegistrationIdentifier: Any]() | ||
|
||
/// Create new instance of ``Container`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Create new instance of ``Container`` | |
/// Create new instance of ``AsyncContainer`` |
|
||
/// Register a dependency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Register a dependency | |
/// Register a dependency |
/// - Parameters: | ||
/// - type: Type of the dependency that should be resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no type
parameter.
/// If the container doesn't contain any registration for a dependency with the given type or if an argument of a different type than expected is passed, a runtime error occurs | ||
/// | ||
/// - Parameters: | ||
/// - type: Type of the dependency that should be resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no type
parameter.
resolvedDependency1 = nil | ||
|
||
XCTAssertNil(resolvedDependency1, "Shared instance wasn't released") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this testing 🤔?
Added new AsyncContainer, with async registration and resolution of dependencies.