-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Scope annotation doesn't work on a provider functions #464
Comments
You're right! In the code example, the The correct code should be: @AppSingleton
@Component
abstract class AppComponent {
@AppSingleton
@Provides // <-- Required annotation
abstract fun provideAuthService(): AuthService
} |
It doesn't help because |
Hey @terrakok I believe that might be the intended behavior or a known limitation. When compiling, you should see a KSP warning about it, something like:
|
My cases are:
|
You might be able to achieve your use case using
Then, in your consumers, you just need to use the
Hope this helps! |
Yes, thank you for the idea. but it seems like a boilerplate. I wish the DI framework would help with that |
I'm not sure if my example was misleading, but you don’t actually need In your case, the only thing you really need is:
Everything else can most likely stay as it is. If you're familiar with Dagger, it's a similar approach to using a custom annotation or the To me, it doesn't really feel like boilerplate 😅. What kind of approach do you think would help reduce this even more? |
tl;dr: It seems you're confusing abstract properties/functions in components which are for retrieval with the side that provides instances. Scope annotations only seem to be supported at the providing side. I'm new to
That's for providing instances. We then use abstract properties or functions in components to retrieve instances. The example in the original post is confusing (to me at least), because it's using an abstract function to retrieve instances while at the same time using the With that out of the way: Scope annotations seem to be supported only at the providing side, not the retrieving side. So... If you're in control of the class to inject, you
That's it. Alternatively you must provide the instance yourself, so you
If anything here's wrong, I apologize in advance. Using this to fact-check my understanding 😅 |
Maybe I missed something, but the code:
generates a regular getter:
but if I mark the AuthService class
it works as expected
The text was updated successfully, but these errors were encountered: