question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MembersInjector for late injection

See original GitHub issue

AssistedInject only works for construction injection. Dagger on the other hand is able to inject stuff after construction with *_MembersInjector for some @Inject lateinit var dep: Dependency.

Is it somehow possible to have this for AssistedInject?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JakeWhartoncommented, Mar 26, 2021

FYI this is no longer a problem as AssistedInjection has moved to Dagger and all that’s left is inflation injection. We can add special handling for MembersInjector now.

1reaction
mlykotomcommented, Dec 16, 2019

I agree, members injection seems like a terrible thing.

The reason is android ViewModel with inheritance:

  • we have “pure” Dagger with ViewModels
  • all ViewModels inherit from some BaseViewModel class
  • for some historical reason (🤷‍♂ ) there’s members injection in the BaseViewModel, therefore when inheriting from the base, it doesn’t need to have inject param in all inherited constructors
  • we’d like to add AssistedInject to the project, so that we can use SavedStateHandle
  • if we do that, you never can access the members injection.

I know, that it seem like a terrible thing, but also if (for some reason) you have members injection without inheritance, it’s the same - no warning, crashes at runtime.

I was checking briefly how the MembersInjector works and for specific class it includes even parent MembersInjector, e.g for SomeViewModel inheriting BaseViewModel, it properly injects SomeViewModel dependencies and also BaseViewModel dependencies.

This means, that injecting MembersInjector<TheClass> into generated factory should (?) be safe and sufficient.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MembersInjector for late injection · Issue #130 - GitHub
The reason assisted inject only works for constructor injection is that you cannot ask Dagger to partially call a constructor and then partially ......
Read more >
MembersInjector - Dagger
Injects dependencies into the fields and methods on instances of type T . Ignores the presence or absence of an injectable constructor.
Read more >
Constructor injection cannot find symbol method inject members
When injecting class through constructor injection it's throwing an error that it cannot find symbol. If I provide the dependency through an ...
Read more >
Deep dive into Dagger generated code (part 2) - ProAndroidDev
This is when members-injection comes to the rescue: Dagger generates a members-injector for classes with @Inject applied to a field or a method....
Read more >
Diesel Fuel Injection - DieselNet
Due to the mechanical response of the injector, there can be a delay between the indicated SOI and the actual SOI when fuel...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found