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

Cumbersome injection with generics #188

Open
emartynov opened this issue Mar 18, 2020 · 3 comments
Open

Cumbersome injection with generics #188

emartynov opened this issue Mar 18, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@emartynov
Copy link

As an exercise purpose, I'm trying to add Dagger Reflect to Plaid project. After all necessary changes to make project compile I got runtime crash.

The issue is that HomeActivity should be injected by HomeComponent. The issue is that HomeComponent doesn't declare the inject method directly but rather implements generic injector interface BaseActivityComponent. Which implements BaseComponent that has generic method

fun inject(target: T)

During debug, I see that reflection is looking to parameter type of the method declaration which is resoled to Object rather than taking the type of the passed parameter HomeActivity.

I wonder what are you thoughts about the issue and the approach taken in the plaid app?

@JakeWharton
Copy link
Owner

The support of generics is lacking. There's also #135 tracking its support on modules.

@JakeWharton JakeWharton added the bug Something isn't working label Mar 24, 2020
@catellie
Copy link

catellie commented Nov 5, 2020

I've spent a fair bit of time trying to get dagger reflect to work in a large project and although most things CAN be worked around with reasonable effort, the lack of support for generics is what blocks me - eliminating them in this particular code base is sadly not a tempting approach at the moment. I will report my other findings in other tickets.

@catellie
Copy link

catellie commented Nov 5, 2020

In case anyone else digs into this, I found it useful to catch the unwanted generics at this point in the code in the debugger and then I could peek around in the scope to try to figure out what I really wanted:

(If your code base is small enough you may even be able to fiddle the dependency key at this stage, but...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants