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

ContributesAndroidInjector support for androidx.lifecycle.ViewModel #1271

Closed
sh4wn opened this issue Sep 3, 2018 · 10 comments · Fixed by #1726
Closed

ContributesAndroidInjector support for androidx.lifecycle.ViewModel #1271

sh4wn opened this issue Sep 3, 2018 · 10 comments · Fixed by #1726

Comments

@sh4wn
Copy link

sh4wn commented Sep 3, 2018

is there any plan for support androidx.lifecycle.ViewModel with @ContributesAndroidInjector?

@Vichy97
Copy link

Vichy97 commented Sep 8, 2018

Also wondering this same thing

@wlodzix
Copy link

wlodzix commented Sep 13, 2018

+1

@ronshapiro
Copy link

We need to think through a few things, but the short answer is yes.

@Vichy97
Copy link

Vichy97 commented Sep 13, 2018

Is there a timeline on that?

@igokoro
Copy link

igokoro commented Oct 21, 2018

Would be really useful. Already got burned by this when implemented such injection myself. It turns out, depending on how/when you inject Fragment (in my case), dagger may "help" retain a "cleared" ViewModel instance. A quick fix in my case was to use Provider<> to get a just-in-time "alive" instance of my ViewModel.

It would also be extremely convenient if dagger could generate ViewModel Factories. From what I understand, the thing is a necessary (evil) piece of boilerplate code required by the framework. It has no other development value. Dagger could derive Factory implementation from injectable ViewModel constructor.

@matejdro
Copy link

Dagger could derive Factory implementation from injectable ViewModel constructor.

See my comment here, you can create that factory easily yourself.

ZacSweers added a commit to ZacSweers/dagger that referenced this issue Jan 17, 2020
Resolves google#1652
Resolves google#1619
Resolves google#1248
Resolves google#1489
Resolves google#1444
Resolves google#1313
Resolves google#1264

Enables better support for newer androidx subprojects like google#1271, but I feel we need to start somewhere. This unblocks that by making the initial move to androidx as a namespace, and then splitting up newer artifacts out of this (and progressively making dagger-android-support increasingly just a shim that delegates to them) is a healthy approach.
cpovirk pushed a commit that referenced this issue Jan 28, 2020
Update imports and dependencies to use AndroidX APIs.
For backwards compatibility, produce two new artifacts,
"dagger-android-legacy" and "dagger-android-support-legacy" that are
dejetified artifacts of the AndroidX versions.

Resolves #1652
Resolves #1619
Resolves #1489
Resolves #1444
Resolves #1313
Resolves #1271
Resolves #1248
Resolves #1264

Co-authored-by: Zac Sweers <zsweers@slack-corp.com>

RELNOTES=Migrate dagger-android to AndroidX.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=291051989
danysantiago added a commit that referenced this issue Jan 28, 2020
Update imports and dependencies to use AndroidX APIs.
For backwards compatibility, produce two new artifacts,
"dagger-android-legacy" and "dagger-android-support-legacy" that are
dejetified artifacts of the AndroidX versions.

Resolves #1652
Resolves #1619
Resolves #1489
Resolves #1444
Resolves #1313
Resolves #1271
Resolves #1248
Resolves #1264

Co-authored-by: Zac Sweers <zsweers@slack-corp.com>

RELNOTES=Migrate dagger-android to AndroidX.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=291051989
@danysantiago danysantiago reopened this Jan 29, 2020
@Chang-Eric
Copy link
Member

I'm closing this since with the release of Hilt and the Jetpack extension for ViewModels using Hilt, I think this feature request for dagger.android is unlikely to be done.

@tir38
Copy link

tir38 commented Aug 17, 2020

This is what @Chang-Eric is referring to: https://developer.android.com/training/dependency-injection/hilt-jetpack#viewmodels

Sadly I wish there was a "vanilla" Dagger (aka w/out dagger-android or Hilt) way of doing this.

@tasomaniac
Copy link

Vanilla Dagger is platform agnostic. That's why it is vanilla 😉

@tir38
Copy link

tir38 commented Aug 24, 2020

Yeah I was complaining about ViewModel implementation, not Dagger =) It's a bummer they didn't give us constructor access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants