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

feat: Async init #19

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open

feat: Async init #19

wants to merge 9 commits into from

Conversation

robha141
Copy link

Added new AsyncContainer, with async registration and resolution of dependencies.

@robha141 robha141 self-assigned this Dec 17, 2024
@robha141 robha141 marked this pull request as ready for review December 19, 2024 10:38
Copy link

@cejanen cejanen left a 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
Copy link

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad 😢

Copy link
Author

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) {
Copy link

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

Copy link
Author

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 😄

Copy link
Author

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 😄

@robha141 robha141 requested a review from cejanen January 7, 2025 07:46
Copy link

@ipek ipek left a 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``
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Create new instance of ``Container``
/// Create new instance of ``AsyncContainer``

Comment on lines +37 to +38

/// Register a dependency
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Register a dependency
/// Register a dependency

Comment on lines +45 to +46
/// - Parameters:
/// - type: Type of the dependency that should be resolved
Copy link

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
Copy link

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.

Comment on lines +45 to +47
resolvedDependency1 = nil

XCTAssertNil(resolvedDependency1, "Shared instance wasn't released")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this testing 🤔?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants