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

Support arguments for scope annotations #377

Closed
vRallev opened this issue Apr 18, 2024 · 2 comments · Fixed by #379
Closed

Support arguments for scope annotations #377

vRallev opened this issue Apr 18, 2024 · 2 comments · Fixed by #379
Labels
enhancement New feature or request

Comments

@vRallev
Copy link
Contributor

vRallev commented Apr 18, 2024

For each scope we need to define a new scope annotation, e.g.

import me.tatarka.inject.annotations.Scope

@Scope annotation class SingleInAppScope
@Scope annotation class SingleInLoggedInScope
@Scope annotation class SingleInRendererScope
...

Rather, I'd like to define a single annotation and use different arguments:

@Scope
annotation class SingleIn(val scope: KClass<*>)

Then I only need to define new class references and can reuse the same scope:

@SingleIn(AppScope::class)
@SingleIn(LoggedInScope::class)
...

The challenge is that more argument types such as ints, strings and enums must be supported for this.

Note that scope annotations using this mechanism today compile fine, but @SingleIn(AppScope::class) would be treated the same as @SingleIn(LoggedInScope::class). The argument is ignored for comparisons.

The same should be supported for qualifiers #253.

@evant evant added the enhancement New feature or request label Apr 18, 2024
evant added a commit that referenced this issue Apr 23, 2024
ex: @NamedScope("one") and @NamedScope("two") are now treated as
distinct scopes.

Fixes #377
@evant
Copy link
Owner

evant commented Apr 23, 2024

Interestingly enough the javadoc for Scope says they should not have attributes, but I verified that dagger does support this.

evant added a commit that referenced this issue Apr 23, 2024
ex: @NamedScope("one") and @NamedScope("two") are now treated as
distinct scopes.

Fixes #377
@vRallev
Copy link
Contributor Author

vRallev commented Apr 24, 2024

Many many years ago (around 2017/18) in a conversation with a Dagger 2 maintainer he mentioned that they have to support it now, because many folks rely on it, but it's not part of the standard. They "accidentally" supported it.

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

Successfully merging a pull request may close this issue.

2 participants