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

  Переглядів 125,171

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

КОМЕНТАРІ: 237
@leonardosibela
@leonardosibela Рік тому
Man, first of all, you are THE BEST Android UKposts 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 Рік тому
Thank you 🥺🙏
@John-qt6qk
@John-qt6qk Рік тому
This coment is so sentimental
@emremuhammetengin2085
@emremuhammetengin2085 Рік тому
The best teacher i have ever seen
@manuelsilveriof
@manuelsilveriof 9 місяців тому
This is by far the best explanation of Dagger Hilt I have found online. Not even the official Android Developers' UKposts 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!
@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
@ranjith_uzumaki
@ranjith_uzumaki 11 місяців тому
My man teaches me more than what I learnt from a 4 yearbachelor's degree.
@technics6215
@technics6215 10 місяців тому
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 8 місяців тому
​@@technics6215but that opinion is way too nuanced!
@abiodunmoses2638
@abiodunmoses2638 Рік тому
I am lost for words already. Man is always hitting the nail on the end. Much love ❤️.
@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 :)
@harishodzic3274
@harishodzic3274 11 місяців тому
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!
@shashanknanda7299
@shashanknanda7299 2 місяці тому
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
@henrygalvan9333
@henrygalvan9333 Рік тому
broo thank you, "you never actually call these functions, dagger hilt does", cleared up so much for me!
@attilabacsa2808
@attilabacsa2808 Рік тому
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 Рік тому
Awesome, thank you and keep it up! 🙏
@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!
@jagat.jeeban
@jagat.jeeban Рік тому
You're a great teacher. Hats off to you man!! 🙌 Keep making such types of tutorials on android topics.
@nantiyachomtee2998
@nantiyachomtee2998 Рік тому
The quality of your content is incredibly high, awesome stuff!! Thanks a lot!!
@mandarpawar1423
@mandarpawar1423 Рік тому
Man, you don't know how grateful I am right now! THANK YOU SO MUCH!!!
@nrg4285
@nrg4285 2 місяці тому
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
@behnawm
@behnawm Рік тому
Thanks for the great video! Please consider explaining different scopes and lifecycles for the dependencies too.
@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 :)
@mohinithakkar2172
@mohinithakkar2172 Рік тому
Thank you so much for this! It has covered almost all the features of Dagger Hilt.
@muyassarabdullah1504
@muyassarabdullah1504 3 місяці тому
I always go back to your tutorial because it is very simple and easy to understands from fundamentals point of view
@guitarcat01
@guitarcat01 Рік тому
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 UKposts =) PS: After this video i already implemented Dagger in two of my projects
@PhilippLackner
@PhilippLackner Рік тому
Thanks a lot mate!
@daniellubenov827
@daniellubenov827 Рік тому
Those videos are with the latest and the best practices. Really the best android tutorials out there.
@PhilippLackner
@PhilippLackner Рік тому
🙏🙏🙏
@mymobile550
@mymobile550 Рік тому
Became so curious after watching this tutorial . Just after I implemented this in one of my project including database module.
@rajm2671
@rajm2671 Рік тому
Finallyyy, I learned Dagger-Hilt. Good explanation. Thanks, Philipp
@samasama3482
@samasama3482 3 місяці тому
The perfect explanation of Dagger Hilt I have ever seen! thank you
@senk0n
@senk0n Рік тому
Oh my, thanks to YOU, it's such an easy to understand and implement simple clean arch project for my CV now
@parulsinghal2k5
@parulsinghal2k5 Місяць тому
you slayyyed it!!! 30 minutes video covered almost everything for a person who knew only how to use dagger2 👏
@codingwithtd5196
@codingwithtd5196 5 місяців тому
Thanks man. This is one of the best Dagger Hilt tutorials I found.
@maryfrancegonzales9570
@maryfrancegonzales9570 Рік тому
The KING is BACK! Thanks bro!
@Langi667
@Langi667 Рік тому
Your tutorials are extremely helpful, thank you so much!
@VinothKumar-oo8ye
@VinothKumar-oo8ye 8 місяців тому
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 ;)
@theevan3867
@theevan3867 Рік тому
Thanks Phillip! if you can, can you make a youtube short of app examples that would be considered impressive to get an entry level position? Please. Thanks!!!
@kamertonaudiophileplayer847
@kamertonaudiophileplayer847 Рік тому
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.
@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.
@khalidrinaldy3671
@khalidrinaldy3671 8 місяців тому
you are the best Kotlin Android Developer's teacher, or maybe the best programming teacher i've ever watched
@7xFuryPlayz
@7xFuryPlayz 11 місяців тому
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 . 🤩☺
@abdelazizyasser3512
@abdelazizyasser3512 Рік тому
thank you so much for this amazing explanation, you're very awesome.I have a question please, how i can use dagger-hilt in my multi module project (modules are library-modules not a feature-modules), i thought to create a separate module object (i mean the dagger-hilt-module that annotated with @Module 😅) for each library-module and provide/bind what i need to inject.am i correct ?
@muhammadsarimmehdi
@muhammadsarimmehdi Рік тому
can you create a dagger-hilt tutorial with custom scopes? That will be very useful to understand, especially for apps with user logins
@pablocruz1302
@pablocruz1302 Рік тому
You are the Best Android development content out there. Thanks for your great content
@PhilippLackner
@PhilippLackner Рік тому
🙏❤️
@fredericoamigo
@fredericoamigo Місяць тому
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.
@RiccardoGabellone
@RiccardoGabellone Рік тому
Hi sir! Great job 💪🏻 Could I ask you a tutorial on how to pre-populate (by using callback) a Room db using Hilt? I am having more than one issue on it 😅 thanks in advance!!
@David-zb8br
@David-zb8br Рік тому
Hey philipp, could you please make a video on how to integrate hilt viemodels and the compose navigation component the correct way? I been meessing around but all i get are unwanted recompositions and overall a mess (should you pass viewmodels between composables using the navigation component? or only the data inside them) Thanks in advance!
@musfickjamil2831
@musfickjamil2831 Рік тому
Philipp you look so fresh in new setup..setup looks awesome. we want setup tour
@tasmanlg
@tasmanlg 11 місяців тому
I have such praise for your content. Thank you so much, truly.
@mithilmehta1501
@mithilmehta1501 Рік тому
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.
@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
@arma6363
@arma6363 11 місяців тому
Hilt would be super easy by your teaching, Thanks alot dear philip
@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!!
@masmmaw
@masmmaw Рік тому
love it 💖 still provide complete information and of course free. Thank you.
@PhilippLackner
@PhilippLackner Рік тому
You're so welcome!
@vikashparajuli
@vikashparajuli Рік тому
Thanks for another great tutorial. Could you please make video on migration from Dagger2 to Hilt?
@OleksandrArtiushenko
@OleksandrArtiushenko Рік тому
hi, can i use interface "module " instead of astract class "module " (all funs inside are abstact)? during binding abstractions. thank you
@ankitverma3932
@ankitverma3932 Рік тому
Please also include the use of entry point. How to use injected classes in attachBaseContext of application or activity ?
@fsfaysalcse
@fsfaysalcse Рік тому
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 Рік тому
Thanks man🙏😅❤️
@TerminalKid
@TerminalKid 6 місяців тому
dude you're Epic, learning a 'lot of good practices from you which saves me time. 👍👍
@saikou_absolute
@saikou_absolute Рік тому
this cool . I had the same problem and solved it with your content. good luck with your work.
@manishpingale6558
@manishpingale6558 Рік тому
I understood hilt like never before 🤯
@rajnarayanan3935
@rajnarayanan3935 Рік тому
What keyboard shortcuts are you using for pulling up the "New Kotlin File/Class" and "New package" dialogs in this video?
@PamontBahktar
@PamontBahktar Рік тому
You're awesome Philipp, thanks so much for this it's really helpful.
@Alchemist10241
@Alchemist10241 Рік тому
This video was the exact info that i have needed.
@pqsk
@pqsk Рік тому
Great video! Thanks so much for the explanation of this library.
@fusing17
@fusing17 Рік тому
will we be seeing a hilt and workmanager video soon? anyways, love your videos
@rahulrvp
@rahulrvp 3 місяці тому
Thanks a lot for making this video. Super helpful!
@programmingwithjackchew903
@programmingwithjackchew903 Рік тому
hi philipp can you do the tutorial regarding signup and login for mvvm jetpack compose (room database)?
@leonkennedy1267
@leonkennedy1267 Місяць тому
Thanks for your videos! It's very helpful! More power to you!
@hossamqandel5303
@hossamqandel5303 Рік тому
Bro.. your content are so profiessnal And clear.. (Sorry for my bad english 😅) I am just want to ask about something I'm always have a problem that i can't or i don't know how to structor the app in my mind and on paper before writing the could Is it possiable to make a full guide video help us to do all steps and structure any app before writing any single line code? 🇪🇬🇩🇪
@ibrahimkhalilshakir2414
@ibrahimkhalilshakir2414 Рік тому
Tnx Again for nice video. If possible make a video about builder pattern/ factory pattern. And why we need to use them.
@iziaulla
@iziaulla Рік тому
Great video man!!! I have just one question though. Where is all the Api parsing done? I thought it was in the view model. An object of the ViewModel is created in MainActivity. Then the UI is assigned its values in the MainActivity, correct?
@John-qt6qk
@John-qt6qk Рік тому
Thank you mate, what about a hide and show floatin btn?
@abhishekpathak7698
@abhishekpathak7698 8 місяців тому
Indeed it was helpful. But i got confused in appcontainer and module of the app components that are created within the appcontainer
@user-xm2hf1sb8n
@user-xm2hf1sb8n 5 місяців тому
Best Video in short time. Good content.
@Sarthakz99
@Sarthakz99 Рік тому
I was looking for the same Auth token use case!! Thanks a lot!!
@ojo_lali_ngaji
@ojo_lali_ngaji Рік тому
great tutorial as always
@luckydevil1601
@luckydevil1601 Рік тому
thank you so much! finally I understood the magic behind this!
@ubersticks
@ubersticks Рік тому
Great job Phillip! When should we use "vm = hiltViewModel()" vs "vm:MyViewModel" by viewModels()" ??
@kitcat2449
@kitcat2449 10 місяців тому
Very clear, thanks!
@omkarkshirsagar8812
@omkarkshirsagar8812 10 днів тому
first time i saw video i dont get it , after seeing video second time now its crystal clear
@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.
@danielvillanuevacastillo359
@danielvillanuevacastillo359 Рік тому
What shortcuts do you use for the new kotlin file and the new package?
@andinaevitha6950
@andinaevitha6950 Рік тому
ITS REALLY WORKED LOL THANK YOU DUDE
@genctasbasi
@genctasbasi 9 місяців тому
This guy is a gem.
@BilalBerek-tl3tq
@BilalBerek-tl3tq 3 місяці тому
perfectly explained dude.
@lioliknumberone1428
@lioliknumberone1428 Рік тому
very interesting and clear tutorial! Thank you very much!
@user-fi5xy4ir7u
@user-fi5xy4ir7u Рік тому
Hey thanks for the video, quick question, is there a way I can use compose destination ksp and dagger hilt same time?
@PhilippLackner
@PhilippLackner Рік тому
sure, they work independently
@user-di3iu9li6c
@user-di3iu9li6c 3 місяці тому
Thank you so much for your excellent explanation dude 😀😃😄😁
@mnouman6736
@mnouman6736 Рік тому
lot of love for you bro
@saabzero
@saabzero Рік тому
I am struggling to find a way to use intent / savedStatehandle when using the ActivityRetainedComponent Module. Neither @ActivityContext nor savedStateHandle work. Can i access my arguments inside ActivityRetainedComponent somehow?
@mouhamadbourouba5382
@mouhamadbourouba5382 Рік тому
i have a simple question i have a Ktor server can i make a api call inside it to OpenWetherApi ?
@atelier_mongame4119
@atelier_mongame4119 Рік тому
This was so helpful!! Thank you
@user-uu8rn6wf4u
@user-uu8rn6wf4u Рік тому
luv
@lukapolic9446
@lukapolic9446 Рік тому
Thank you for this video. Very clear, informative, and organized. How much time have you put in to make something like this ?
@PhilippLackner
@PhilippLackner Рік тому
Thanks! If the topic is already clear to me and doesn't require research like here, a video like this one takes 4-5h
@coldwolf5050
@coldwolf5050 Рік тому
Great video, very helpful 👍
@burakkarabekir2863
@burakkarabekir2863 Рік тому
Nice recap, thx man!
@PhilippLackner
@PhilippLackner Рік тому
Welcome!
@chityeag
@chityeag Рік тому
Awesome! Thank You Philip
@PhilippLackner
@PhilippLackner Рік тому
Welcome!
@SapphireStudioart
@SapphireStudioart Рік тому
Great video! Well explained, thank you
@winsonmac
@winsonmac Рік тому
Great sharing! I learned new things from you like @Binds and Lazy Injection
@hibroonyancha
@hibroonyancha 4 місяці тому
I love the videos straight forward Explanation but my app keeps crushing when implementing the hilt viewmodel ,with an error of you cannot access the NavBackStackEntry's viewmodels after the navback stack entry is destroyed. Please someone help
@realurah
@realurah Рік тому
damn... you are such a good teacher man
@PhilippLackner
@PhilippLackner Рік тому
Thank you!🙏🙏
@kamrulhuqmaroof113
@kamrulhuqmaroof113 Рік тому
Wow man it really works!
@George-nx8zu
@George-nx8zu Рік тому
I keep getting this error when I try to build: Libraries using reflection such as annotation processors need to be updated manually to add support for androidx. Is it related to dagger hilt?
@chrisperey561
@chrisperey561 Рік тому
you are literally the best
Full Guide to Manual Dependency Injection + Removing Dagger
14:50
Philipp Lackner
Переглядів 32 тис.
What Is the Best Architecture for Android Apps?
17:57
Philipp Lackner
Переглядів 52 тис.
одни дома // EVA mash @TweetvilleCartoon
01:00
EVA mash
Переглядів 4,9 млн
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Переглядів 143 тис.
Все про Dagger Hilt в Android Studio + Kotlin
52:11
Neco Ru
Переглядів 10 тис.
Hilt and dependency injection - MAD Skills
13:06
Android Developers
Переглядів 45 тис.
Full Guide to Dependency Scopes with Dagger-Hilt - Android Studio Tutorial
20:40
Hilt - лёгкий старт в Dagger
32:26
Android Broadcast. Все об Андроид разработке
Переглядів 14 тис.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Переглядів 708 тис.
What is the Context? - Android Basics 2023
11:22
Philipp Lackner
Переглядів 45 тис.
Most overpowered way to build mobile apps?
8:33
Beyond Fireship
Переглядів 675 тис.