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

Allow using ContributesTo to contribute provisions #728

Open
gabrielittner opened this issue Jul 22, 2023 · 1 comment
Open

Allow using ContributesTo to contribute provisions #728

gabrielittner opened this issue Jul 22, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@gabrielittner
Copy link
Contributor

gabrielittner commented Jul 22, 2023

The goal would be to allow writing this

@ContributesTo(AppScope::class)
fun provideOkHttpClient(): OkHttpClient = ...

which generates something equivalent to

@Module
@ContributesTo(AppScope::class)
object OkHttpClientModule {
  fun provideOkHttpClient(): OkHttpClient = ...
}

This would almost completely avoid the need to create module classes. Other than plain injected classes any contribution to a component would then use a @Contributes... annotation and we wouldn't need another concept like modules. The only scenario that I can think of where you'd still need a module is generic bindings but the most common case for them would be addressed by #726). The original motivation comes from this thread https://androiddev.social/@[email protected]/110722092128294953

An implementation would need to handle scope and qualifier annotations (edit: also multibinding annotations) on the function as well as parameters to the function and their annotations.

It would also be possible to create a @ContributesProvides annotation for this but it would have the same parameters.

If this is something you'd want to support I can take a stab at implementing it.

@gabrielittner gabrielittner changed the title Allow using ContributesTo to contribute provision Allow using ContributesTo to contribute provisions Jul 22, 2023
@bubenheimer
Copy link

You have my vote. This approach can be extended to properties (computed and not), just as in a module: #578

@JoelWilcox JoelWilcox added the enhancement New feature or request label Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants