The Ultimate Dagger-Hilt Guide (Dependency Injection) - Android Studio Tutorial

  Рет қаралды 133,391

Philipp Lackner

Philipp Lackner

Күн бұрын

Dependency injection is a core concept of software development. In this video, I'll show you how you can apply DI in an Android app using Dagger-Hilt.
⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:
pl-coding.com/premium-courses...
💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:
elopage.com/s/philipplackner/...
Subscribe to my FREE newsletter for regular Android, Kotlin & Architecture advice!
pl-coding.com/newsletter
Join this channel to get access to perks:
/ @philipplackner
Get the code here:
github.com/philipplackner/Dag...
Join my Discord server:
/ discord
Regular programming advice on my Instagram page: / _philipplackner_
Checkout my GitHub: github.com/philipplackner
You like my free content? Here you can buy me a coffee:
www.buymeacoffee.com/philippl...
00:00 - What is dependency injection?
06:45 - Setting up Dagger-Hilt
08:25 - Setting up the structure
10:39 - Creating a module
17:20 - Injecting into ViewModels
20:15 - Injecting the ViewModel in the UI
21:40 - Creating the application class
24:05 - Two dependencies of same type
26:20 - Binding abstractions
29:58 - Field injection
31:28 - Lazy injection

Пікірлер: 244
@leonardosibela
@leonardosibela 2 жыл бұрын
Man, first of all, you are THE BEST Android KZbin channel in the whole website. Second, you are just awesome!! You are a great teacher and a very charismatic human being. Last, but not least, I don't know how you don't get tired of making so many great videos. You ARE the best!! Thanks for teaching me so much. It's being a pleasure to have your videos as part of my life.
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Thank you 🥺🙏
@John-qt6qk
@John-qt6qk 2 жыл бұрын
This coment is so sentimental
@emremuhammetengin2085
@emremuhammetengin2085 2 жыл бұрын
The best teacher i have ever seen
@manuelsilveriof
@manuelsilveriof 11 ай бұрын
This is by far the best explanation of Dagger Hilt I have found online. Not even the official Android Developers' KZbin channels explain it like you do. Thank you so much!!
@alexeysimchenko7494
@alexeysimchenko7494 Жыл бұрын
I use dagger/hilt every day but usually as copy/paste so today I decided to finally get known how it works. Your explanation is the best of several that I saw today!
@priyanshugupta7904
@priyanshugupta7904 Жыл бұрын
I am a student I can't buy u a coffee but I can like and share your video with my friends. Amazing Teaching :)
@shashanknanda7299
@shashanknanda7299 4 ай бұрын
This is the most easy to understand explaination that I've ever found on dagger-hilt till now, you explained each topic very consicely yet clearly
@moforemmanuel158
@moforemmanuel158 Жыл бұрын
your tutorials are the best because you take time to explain the subtle concepts behind the code which is rare from other tutorials i just had to watch this once the get the whole scope of what DI with Hilt is and it implementations
@abiodunmoses2638
@abiodunmoses2638 2 жыл бұрын
I am lost for words already. Man is always hitting the nail on the end. Much love ❤️.
@mandarpawar1423
@mandarpawar1423 Жыл бұрын
Man, you don't know how grateful I am right now! THANK YOU SO MUCH!!!
@henrygalvan9333
@henrygalvan9333 Жыл бұрын
broo thank you, "you never actually call these functions, dagger hilt does", cleared up so much for me!
@harishodzic3274
@harishodzic3274 Жыл бұрын
I always try to give credit where credit is deserved. And you my man are pure gold. I just stumbled on your content and I'm happy for that. Fast, to the point, full of valuable information. Keep on going this is great. I will subscribe, upvote, like. Wish you a good luck in the upcoming days!
@tonyalbanese6446
@tonyalbanese6446 Жыл бұрын
I still can't believe how terrific these videos are. You explanations are superb. Thank you so much for taking the time to make this content.
@PhilippLackner
@PhilippLackner Жыл бұрын
Thank you, happy to help!
@attilabacsa2808
@attilabacsa2808 2 жыл бұрын
Thank you, excellent content as always. When I decided to switch carrier and become an Android dev, your channel was one of the main sources to learn the basics. Keep up the good work! 💯
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Awesome, thank you and keep it up! 🙏
@jagat.jeeban
@jagat.jeeban 2 жыл бұрын
You're a great teacher. Hats off to you man!! 🙌 Keep making such types of tutorials on android topics.
@mohinithakkar2172
@mohinithakkar2172 Жыл бұрын
Thank you so much for this! It has covered almost all the features of Dagger Hilt.
@nantiyachomtee2998
@nantiyachomtee2998 Жыл бұрын
The quality of your content is incredibly high, awesome stuff!! Thanks a lot!!
@muyassarabdullah1504
@muyassarabdullah1504 5 ай бұрын
I always go back to your tutorial because it is very simple and easy to understands from fundamentals point of view
@daniellubenov827
@daniellubenov827 Жыл бұрын
Those videos are with the latest and the best practices. Really the best android tutorials out there.
@PhilippLackner
@PhilippLackner Жыл бұрын
🙏🙏🙏
@rajm2671
@rajm2671 Жыл бұрын
Finallyyy, I learned Dagger-Hilt. Good explanation. Thanks, Philipp
@maryfrancegonzales9570
@maryfrancegonzales9570 2 жыл бұрын
The KING is BACK! Thanks bro!
@samasama3482
@samasama3482 5 ай бұрын
The perfect explanation of Dagger Hilt I have ever seen! thank you
@khalidrinaldy3671
@khalidrinaldy3671 10 ай бұрын
you are the best Kotlin Android Developer's teacher, or maybe the best programming teacher i've ever watched
@nrg4285
@nrg4285 3 ай бұрын
I normally blast through these tutorials but this one took a solid 1-2 hours because of coding and note-taking at the same time and there was so much good content. For example it takes 7 individual scrolls to get through the notes top to bottom, that's a lot more than usual
@parulsinghal2k5
@parulsinghal2k5 3 ай бұрын
you slayyyed it!!! 30 minutes video covered almost everything for a person who knew only how to use dagger2 👏
@guitarcat01
@guitarcat01 2 жыл бұрын
You always teach in a very patient and simple way and all i can do i really thank you SO MUCH for what you're doing! I'd say more than 60% of what i know about android comes from you. This is by far the greatest android development channel on KZbin =) PS: After this video i already implemented Dagger in two of my projects
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Thanks a lot mate!
@VinothKumar-oo8ye
@VinothKumar-oo8ye 9 ай бұрын
philip lackner, i studied your and workout your Weather app (clean code architecture) course, and i don't understand most of things, then after watching this dependency injection i understand all the doubts i have on the weather app course. super tutorial ;)
@senk0n
@senk0n 2 жыл бұрын
Oh my, thanks to YOU, it's such an easy to understand and implement simple clean arch project for my CV now
@tasmanlg
@tasmanlg Жыл бұрын
I have such praise for your content. Thank you so much, truly.
@codingwithtd5196
@codingwithtd5196 7 ай бұрын
Thanks man. This is one of the best Dagger Hilt tutorials I found.
@ranjith_uzumaki
@ranjith_uzumaki Жыл бұрын
My man teaches me more than what I learnt from a 4 yearbachelor's degree.
@technics6215
@technics6215 11 ай бұрын
This is about a tool / library. Tools and libraries will change over time. Most of the things you learn in school won't change. If you are in engineering school you are not there to learn how to make a hole in metal with one particular kind of machine. You don't need a professor fot that. You are there to know why, when and where you have to make that hole.
@SumriseHD
@SumriseHD 10 ай бұрын
​@@technics6215but that opinion is way too nuanced!
@GoceAnastasovski
@GoceAnastasovski Жыл бұрын
Great video! I finally understood Hilt! I would create a sequel to this video where you focus on unit tests, you write the tests without hilt first and then with Hilt
@PhilippLackner
@PhilippLackner Жыл бұрын
I do have a hilt testing video on my channel :)
@mymobile550
@mymobile550 2 жыл бұрын
Became so curious after watching this tutorial . Just after I implemented this in one of my project including database module.
@arma6363
@arma6363 Жыл бұрын
Hilt would be super easy by your teaching, Thanks alot dear philip
@Langi667
@Langi667 Жыл бұрын
Your tutorials are extremely helpful, thank you so much!
@AliAhmad-di5ck
@AliAhmad-di5ck Ай бұрын
Thanks a lot, I now can understand DI really well.
@pablocruz1302
@pablocruz1302 2 жыл бұрын
You are the Best Android development content out there. Thanks for your great content
@PhilippLackner
@PhilippLackner 2 жыл бұрын
🙏❤️
@rahulrvp
@rahulrvp 5 ай бұрын
Thanks a lot for making this video. Super helpful!
@user-xm2hf1sb8n
@user-xm2hf1sb8n 7 ай бұрын
Best Video in short time. Good content.
@pqsk
@pqsk Жыл бұрын
Great video! Thanks so much for the explanation of this library.
@behnawm
@behnawm 2 жыл бұрын
Thanks for the great video! Please consider explaining different scopes and lifecycles for the dependencies too.
@LinaSarkar7307
@LinaSarkar7307 Жыл бұрын
its priceless. the slickness and the passion of the devs. priceless. what is cheaper and better than soft? Piracy is NOT the answer if you
@luckydevil1601
@luckydevil1601 Жыл бұрын
thank you so much! finally I understood the magic behind this!
@leonkennedy1267
@leonkennedy1267 2 ай бұрын
Thanks for your videos! It's very helpful! More power to you!
@Alchemist10241
@Alchemist10241 2 жыл бұрын
This video was the exact info that i have needed.
@TerminalKid
@TerminalKid 8 ай бұрын
dude you're Epic, learning a 'lot of good practices from you which saves me time. 👍👍
@masmmaw
@masmmaw Жыл бұрын
love it 💖 still provide complete information and of course free. Thank you.
@PhilippLackner
@PhilippLackner Жыл бұрын
You're so welcome!
@avinashreddy9565
@avinashreddy9565 9 ай бұрын
Great Explanation!!! Very Easy to understand...
@PamontBahktar
@PamontBahktar Жыл бұрын
You're awesome Philipp, thanks so much for this it's really helpful.
@lioliknumberone1428
@lioliknumberone1428 Жыл бұрын
very interesting and clear tutorial! Thank you very much!
@saikou_absolute
@saikou_absolute Жыл бұрын
this cool . I had the same problem and solved it with your content. good luck with your work.
@fredericoamigo
@fredericoamigo 2 ай бұрын
I’m so grateful for all of your brilliant videos on Android development in kotlin and jetpack compose. Thank you so much for this! If I might suggest a future video: how to use foreground location for in a MVVP app using datasource-repository-viewmodel architecture.
@Hoseinsadonasl-jo4dm
@Hoseinsadonasl-jo4dm Ай бұрын
Really awsome Philipp
@andinaevitha6950
@andinaevitha6950 Жыл бұрын
ITS REALLY WORKED LOL THANK YOU DUDE
@musfickjamil2831
@musfickjamil2831 2 жыл бұрын
Philipp you look so fresh in new setup..setup looks awesome. we want setup tour
@Sarthakz99
@Sarthakz99 Жыл бұрын
I was looking for the same Auth token use case!! Thanks a lot!!
@genctasbasi
@genctasbasi 10 ай бұрын
This guy is a gem.
@kitcat2449
@kitcat2449 Жыл бұрын
Very clear, thanks!
@BilalBerek-tl3tq
@BilalBerek-tl3tq 4 ай бұрын
perfectly explained dude.
@mithilmehta1501
@mithilmehta1501 2 жыл бұрын
Hey Philipp, I am from India and I really love your videos and it helps a lot. Thanks! God bless you and keep up the good work. Your explanation are so simple that even a fresher can understand. 😊
@RaajKanchan
@RaajKanchan Жыл бұрын
Hey Mithil, I am new to Dagger Hilt. Can you help me, I want to pass String value from Activity to an AppModule. How can I do that?
@mithilmehta1501
@mithilmehta1501 Жыл бұрын
@@RaajKanchan why do you want to pass string to app module from activity? Do you want to pass it to next activity?
@RaajKanchan
@RaajKanchan Жыл бұрын
​@@mithilmehta1501 No, no its just an example. Let me give you the example. ----------------------------------------------------- class Customer @Inject constructor(@CName val customerName: String, private val age: Int) { fun printCustomerDetails() { println("$TAG :: $customerName is $age old") } } @Module @InstallIn(SingletonComponent::class) object AppModule { @Provides @Singleton @CName fun provideCustomerName() = "Mithil Mehta" @Provides @Singleton fun provideCustomerAge() = 24 } @Qualifier @Retention(AnnotationRetention.BINARY) annotation class CName @Inject lateinit var customer: Customer customer.printCustomerDetails() ----------------------------------------- Here in the module I am providing CustomerName and CustomerAge statically. Not dynamically. I just want to learn how can I do that.
@mithilmehta1501
@mithilmehta1501 Жыл бұрын
@@RaajKanchan bro, you are getting it wrong. This is not something to be passed usong dagger. This data which should be passed either from activity to another Activity or else load from network for that particular screen. Dagger should be used to inject those dependencies which screen requires but doesn't care how it is created. So, as per my understanding your usecase is incorrect.
@kamrulhuqmaroof113
@kamrulhuqmaroof113 Жыл бұрын
Wow man it really works!
@manishpingale6558
@manishpingale6558 Жыл бұрын
I understood hilt like never before 🤯
@chitye-aung
@chitye-aung 2 жыл бұрын
Awesome! Thank You Philip
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Welcome!
@SapphireStudioart
@SapphireStudioart Жыл бұрын
Great video! Well explained, thank you
@kamertonaudiophileplayer847
@kamertonaudiophileplayer847 2 жыл бұрын
A very frequently my class functionality requires the context. But it is available only in an activity. So I was really frustrated until watched you video. Now, I just tell - inject! That's it, simple and elegant.
@winsonmac
@winsonmac 2 жыл бұрын
Great sharing! I learned new things from you like @Binds and Lazy Injection
@user-di3iu9li6c
@user-di3iu9li6c 5 ай бұрын
Thank you so much for your excellent explanation dude 😀😃😄😁
@chrisperey561
@chrisperey561 Жыл бұрын
you are literally the best
@bdjobstv8575
@bdjobstv8575 Жыл бұрын
thanks a lot!!! so nice reverb
@whogashaga666
@whogashaga666 Жыл бұрын
Thanks for sharing this video.
@amirnaderlo3045
@amirnaderlo3045 Жыл бұрын
it was so helpful,Thanks
@toniwincent6653
@toniwincent6653 Жыл бұрын
You are the best at explaining this so that I understand! Thank you so much! When I get my first job as a developer I will buy you coffey! 🙂
@PhilippLackner
@PhilippLackner Жыл бұрын
Thank you, happy to help!!
@atelier_mongame4119
@atelier_mongame4119 Жыл бұрын
This was so helpful!! Thank you
@xandrviking1113
@xandrviking1113 Жыл бұрын
Thanks Philipp 👏🤝
@MrVipulLal
@MrVipulLal 8 ай бұрын
Your videos are all amazing 🙏👍👍👌💯
@coldwolf5050
@coldwolf5050 2 жыл бұрын
Great video, very helpful 👍
@ojo_lali_ngaji
@ojo_lali_ngaji 2 жыл бұрын
great tutorial as always
@user-uu8rn6wf4u
@user-uu8rn6wf4u Жыл бұрын
luv
@tarekrefaei90
@tarekrefaei90 Жыл бұрын
Totally Awesome ... Thanks alot ..
@fsfaysalcse
@fsfaysalcse 2 жыл бұрын
Sometimes I thought you might be a superhero 😜 And you Come from a different universe. Best of luck, brother. I am your biggest fan from Coroutines video playlist ❤
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Thanks man🙏😅❤️
@realurah
@realurah Жыл бұрын
damn... you are such a good teacher man
@PhilippLackner
@PhilippLackner Жыл бұрын
Thank you!🙏🙏
@7xFuryPlayz
@7xFuryPlayz Жыл бұрын
now i understand how to use Hilt properly , within my project but i have still some doubts within my mind about clean architecture implementation, hope so i will figure them too . but thanks for this complete video . 🤩☺
@VV-bo7rx
@VV-bo7rx 7 ай бұрын
Thank You very much!
@mnouman6736
@mnouman6736 2 жыл бұрын
lot of love for you bro
@abacaabaca8131
@abacaabaca8131 Ай бұрын
The purpose of Dependency Injection is that you can share the same reference to an object even when the objects that wants to share it have different lifetime. For example, if I have 3 classes namely `Time`, `A`, and `B`. let say Time class is used for benchmarking or profiling your program. It can be used to detect how much time each functions/methods are executed at runtime. This means you need to create one single instance of Time class so that A and B can refer to this object. Because, if you create two different objects for A and B , maybe the timing is not continuous and so give wrong result. When you have dependency Injection, you have other class that kind of manage the creation of object and it's lifetime. Meaning, if A and B lives in different lifetime, they still be able to share the same reference to Time instance object. For example, if A is created first, then the dependency Injection will also create Time object. After A is deallocated, the dependency Injection will save the state of this Time object that have some state profiling instance of A. Then Time will get deallocated. Then when B is created, the dependency Injection will create the same object of Time with the same last state for A. Meaning as if Time object is reborn again but with the same state when it was when A is about to die.
@jafxc2383
@jafxc2383 2 жыл бұрын
Thank you for sharing!!!
@burakkarabekir2863
@burakkarabekir2863 2 жыл бұрын
Nice recap, thx man!
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Welcome!
@ashishgautam2842
@ashishgautam2842 Жыл бұрын
bro as i'm seeing my growth, i have seen growth in you too..actually / definitely your ahead me but somewhere i feelled sync between us.
@kamronqobilov1954
@kamronqobilov1954 2 жыл бұрын
You are very smart man
@RahulKumar-un6ur
@RahulKumar-un6ur Жыл бұрын
Wow....what an amazing,clear and short to the point explanation. Out of curiosity, I would like to ask a question please. Can we keep the AppModule a normal class instead of object? Is it recommend to make a module (of course, not a binding module) object instead of a normal class? I tested and both works. Tons of thanks for your time and this amazing explanation.
@samsammaniamantap
@samsammaniamantap 9 ай бұрын
this is so helpful
@saurabhyadav-sz9rx
@saurabhyadav-sz9rx Жыл бұрын
It was great!
@680086
@680086 Жыл бұрын
Very useful video
@yasserakbbach7342
@yasserakbbach7342 2 жыл бұрын
My hero ✨️
@nithinjoseph6097
@nithinjoseph6097 2 жыл бұрын
Great video ✌️
@abdomostafa4512
@abdomostafa4512 Жыл бұрын
You're my legend
@MrMrusman2123
@MrMrusman2123 9 ай бұрын
great and simple🤘
@georgegichura8848
@georgegichura8848 Жыл бұрын
Worked, thx
@gastonsaillen2226
@gastonsaillen2226 Жыл бұрын
I think we should use @InstallIn(ViewModelComponent::class.java) since the repository lives inside a ViewModel, in the meantime that we inject the repository inside the ViewModel, hilt will then delete this repository instance when the ViewModel is cleared (onCleared is called, ViewModel is destroyed because its activity/fragment does not need it anymore). If we do it with the SingletonComponent it will be tied up with the Application class you created, and hence, the repository instance will outlive the ViewModel. Another way of not using @Named could be to use @Qualifiers which can be more verbose on for example creating two different okHttp clients Great video Philipp, it contains a lot of excellent suggestions !
@omkarkshirsagar8812
@omkarkshirsagar8812 2 ай бұрын
first time i saw video i dont get it , after seeing video second time now its crystal clear
@mohannadyoussef8683
@mohannadyoussef8683 2 жыл бұрын
Thank you so much. you are the best.
@slotgacor8165
@slotgacor8165 Жыл бұрын
All the best,
Full Guide to Manual Dependency Injection + Removing Dagger
14:50
Philipp Lackner
Рет қаралды 35 М.
Получилось у Вики?😂 #хабибка
00:14
ХАБИБ
Рет қаралды 5 МЛН
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 22 МЛН
Пробую самое сладкое вещество во Вселенной
00:41
The Ultimate Package Structure Guide for Android Developers
12:10
Philipp Lackner
Рет қаралды 35 М.
5 Fatal Coroutine Mistakes Nobody Tells You About
18:15
Philipp Lackner
Рет қаралды 84 М.
Hilt and dependency injection - MAD Skills
13:06
Android Developers
Рет қаралды 46 М.
Основы DI и Dagger, как работает, настройка в проекте
17:31
Android Broadcast. Все об Андроид разработке
Рет қаралды 66 М.
Android Hilt Tutorial - Injecting Dependencies with Hilt
13:23
Simplified Coding
Рет қаралды 27 М.
THIS Compose-State Mistake Leads to Problems In Your Code
7:58
Philipp Lackner
Рет қаралды 38 М.
Hilt Dependency Injection (Kotlin Beginner Example)
21:20
CodingWithMitch
Рет қаралды 42 М.
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Рет қаралды 192 М.