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

Create Resolvable macro #232

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Create Resolvable macro #232

wants to merge 1 commit into from

Conversation

skorulis-ap
Copy link
Collaborator

@skorulis-ap skorulis-ap commented Jan 23, 2025

Adds a macro which generates a static function to create the type using a resolver.
The macro is able to replace the need for SwinjectAutoregistration in a way that is compile time safe as well as adding support for named parameters and default values.

@Resolvable<Resolver>
init(string: String, int: @Named("balance") balance) { ... }

// Generates
static func make(resolver: Resolver) -> Self {
  return .init(
    string: resolver.string(),
    balance: resolver.int(name: .balance)
  )
}

One caveat is that this will not work with services using getter-named as the macro isn't aware of the custom name. This can be dealt with by either minimising the use of getter-named (already in progress) or by always generating the default accessor.

@skorulis-ap skorulis-ap force-pushed the skorulis/macros branch 3 times, most recently from e7e2de2 to dfafbd0 Compare January 23, 2025 01:47
XCTAssertEqual(defaultedService?.value, 2)
}

/* Disabled due to import issues
Copy link
Collaborator Author

@skorulis-ap skorulis-ap Jan 23, 2025

Choose a reason for hiding this comment

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

I can't figure out why @Argument and @Named aren't available in this file.

@skorulis-ap skorulis-ap marked this pull request as ready for review January 23, 2025 02:31
@skorulis-ap skorulis-ap requested a review from bradfol January 23, 2025 02:31
@skorulis-ap skorulis-ap force-pushed the skorulis/macros branch 2 times, most recently from 8cb793a to 53d606d Compare January 27, 2025 23:01
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.

1 participant