Scoping with HILT (Dagger2)

  Рет қаралды 17,626

CodingWithMitch

CodingWithMitch

Күн бұрын

The best android courses in the world: codingwithmitch.com/
Watch the HILT course here (FREE): codingwithmitch.com/courses/h...
In this video I go over how the scoping works for Hilt Dagger2 on Android. Some of the scopes that hilt will generate for you are: @Singleton, @RetainedActivityScope, @ActivityScope, @FragmentScope, @ViewScope, @ServiceScope and more.
Instagram: / codingwithmitch
Twitter: / mitch_tabian
.
.
#AndroidDev

Пікірлер: 32
@sandeepemekar4014
@sandeepemekar4014 4 жыл бұрын
Thank you for the great Tutorial, Mitch!
@thesoftwareengineer_
@thesoftwareengineer_ 4 жыл бұрын
Thanks Mitch .... This is very helpful
@gunjotsingh3638
@gunjotsingh3638 2 жыл бұрын
Loved it 🙌🏻
@learnwithmicrostar
@learnwithmicrostar 3 жыл бұрын
Thank you BRO for the great tutorial !
@thai1711994
@thai1711994 4 жыл бұрын
Very helpful. Thank you
@jaserq
@jaserq 4 жыл бұрын
Perfect
@soumyaghosh5915
@soumyaghosh5915 3 жыл бұрын
Bro you are Awesome
@oscarperry641
@oscarperry641 4 жыл бұрын
pioneer
@codingwithmitch
@codingwithmitch 4 жыл бұрын
😘
@mattgraves3709
@mattgraves3709 3 жыл бұрын
Ok, now I get it.
@Hackaprende
@Hackaprende 3 жыл бұрын
Thanks a lot! What happens if we use always Singleton Scope? Are we going to have performance issues?
@RonnieOtieno
@RonnieOtieno 3 жыл бұрын
Dagger also throw runtime error, example is if you inject fragment and annotate it with Singleton. You will get an error that dagger doesn't support retained fragment instances or something like that
@yasserahmed3452
@yasserahmed3452 3 жыл бұрын
hi mitch, can you tell me if hilt is better or Kodein to use in di ? and thank you
@amirs6472
@amirs6472 3 жыл бұрын
good
@MohamedElnady001
@MohamedElnady001 4 жыл бұрын
الحب كله يالا Translation: thank you very much
@mohamadsh3874
@mohamadsh3874 3 жыл бұрын
بتغلط ليه يسطا
@tejshah6225
@tejshah6225 2 жыл бұрын
@condingWithMitch, I have created my one helper class which inject It and i have 2 activity. both activity have a different have new object allocation. Means it create a new object every time. why?
@PeteStMartin
@PeteStMartin 2 жыл бұрын
Engagement!
@bhuvneshvarma7843
@bhuvneshvarma7843 3 жыл бұрын
@CodingWithMitch Thanks for such great tutorials..As per your tutorial "Activity Retain Scope gives same scope as View Model- more than activity but due before application die".I don't understand How you assumed that ViewModel lives more than Activity??Bcoz as per docs "ViewModel objects are scoped to the Lifecycle passed to the ViewModelProvider when getting the ViewModel. The ViewModel remains in memory until the Lifecycle it's scoped to goes away permanently: in the case of an activity, when it finishes, while in the case of a fragment, when it's detached."
@eddiej204
@eddiej204 3 жыл бұрын
By the Field injection approach, without define Scope, which component that the instance will be installed in?
@bhuvneshvarma7843
@bhuvneshvarma7843 3 жыл бұрын
By default all bindings of hilt are unscoped.That means that each time your app requests the binding Hilt creates a new instance of needed type
@Tech-To-Logic
@Tech-To-Logic 4 жыл бұрын
Hi Mitch, tell me one thing. Suppose we have 2 activity. And I declared a component as an @ActivityComponent and inject on both activity. Now if I switched to one activity to another, then how destruction of that injected component will happen?
@codingwithmitch
@codingwithmitch 4 жыл бұрын
This is what I'm not clear on. a) Is there an ActivityComponent generated for every activity in the project? b) Or is there a single ActivityComponent that lives as long as there is at least one activity alive I'm leaning heavily towards "b". I don't think it makes sense if you consider scoping. So Probably: 1) ApplicationComponent lives as long as app is alive 2) ActivityRetainedComponent lives as long as there is at least one viewmodel alive 3) ActivityComponent lives as long as there is at least one activity alive 4) FragmentComponent.... etc... I couldn't find anywhere in the docs that explained this in detail.
@Zhuinden
@Zhuinden 4 жыл бұрын
@@codingwithmitch There is an ApplicationComponent that is global. There is an ActivityComponent configured globally, but instance created per each Activity. There is an ActivityRetainedComponent configured globally, but instance created per each Activity (that then places the component into a ViewModel and retrieves it from there if it already exists). There is a FragmentComponent that is configured globally, but instance created per each Activity. There is a hierarchy of Application -> ActivityRetained -> Activity -> Fragment.
@codingwithmitch
@codingwithmitch 4 жыл бұрын
@@Zhuinden So @FragmentScoped'd dependencies injected in "FragmentA" will live as long as ActivityA? And dependencies injected in "FragmentB" will live as long as ActivityB? Assuming FragmentA is a child of ActivityA and FragmentB is a child of ActivityB exclusively? BTW how you know this? Experimentation? Because I did not see this explained in the docs.
@Zhuinden
@Zhuinden 4 жыл бұрын
@@codingwithmitch A combination of Manuel Vivo's Twitter, the generated source code of CustomApplication_HiltComponents.FragmentC, and the source code of Hilt_MainActivity, ActivityComponentManager, and Hilt_SomeFragment and FragmentComponentManager. I haven't read all of the docs, it's kinda long :D
@Zhuinden
@Zhuinden 4 жыл бұрын
The tricky thing I don't really get yet is how custom EntryPoints work.
@astrologykhan8125
@astrologykhan8125 4 жыл бұрын
What news say about hin??
@ChrisAthanas
@ChrisAthanas 3 жыл бұрын
Engage warp engines to 100k
@silver10188
@silver10188 3 ай бұрын
I feel like they are hypocrites, they say don't use static, but this hilt thing is basically static fields that live somewhere.
HILT Constructor Injection Problems
8:02
CodingWithMitch
Рет қаралды 16 М.
Hilt Modules, Binds and Provides (Dagger2)
18:02
CodingWithMitch
Рет қаралды 21 М.
Iron Chin ✅ Isaih made this look too easy
00:13
Power Slap
Рет қаралды 36 МЛН
Gym belt !! 😂😂  @kauermotta
00:10
Tibo InShape
Рет қаралды 18 МЛН
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Рет қаралды 36 М.
Providing Instances of the Same Type with HILT (Dagger2)
7:02
CodingWithMitch
Рет қаралды 11 М.
Hilt - Android Dependency Injection
28:57
Android Developers
Рет қаралды 51 М.
HILT Field Injection and Constructor Injection
9:44
CodingWithMitch
Рет қаралды 25 М.
DO NOT do this in a Software Engineering Interview
7:59
CodingWithMitch
Рет қаралды 9 М.
The Story of Next.js
12:13
uidotdev
Рет қаралды 560 М.
Fragment Constructor Injection with Hilt and Navigation Component
24:38
Advice from a Principal Software Engineer at Amazon (Steve Huynh)
22:45
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 65 МЛН