MembersInjector for late injection
See original GitHub issueAssistedInject 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:
- Created 4 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.I agree, members injection seems like a terrible thing.
The reason is android ViewModel with inheritance:
BaseViewModel
classBaseViewModel
, therefore when inheriting from the base, it doesn’t need to have inject param in all inherited constructorsAssistedInject
to the project, so that we can useSavedStateHandle
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
inheritingBaseViewModel
, it properly injectsSomeViewModel
dependencies and alsoBaseViewModel
dependencies.This means, that injecting
MembersInjector<TheClass>
into generated factory should (?) be safe and sufficient.