Over time, a few things changed in regards to dagger hilt. I made a new video in which I cover the most up to date things and also some more concepts I didn't cover in this one: ua-cam.com/video/bbMsuI2p1DQ/v-deo.html
This is really a complete video about Dagger Hilt and very easy to understand, as Philipp started to explain "if you want to inject 2 strings", you can realize that this video is better than others on UA-cam and in the same way it has enough fundamentals concepts of Hilt so you can start the implementation in your application. Really thanks Sir 🤜🤛
This is an awesome video to easily understand Hilt. Even Google developers also don't teach like this. Thanks a lot, @Philipp Lackner for making this video.
For those having trouble with ViewModel log cat: @Module @InstallIn(ActivityRetainedComponent ::class) object MainModule { // This will only live in main activity // Cannot have @singleton that only lives as long as our activity // Instead of @Singleton, we use activity scoped @ActivityRetainedScoped @Provides @Named("String2") // if we need to access context, say strings file, how? // We used context as a parameter!! // dagger hilt will also figure out which testString1 we will inject!! fun provideTestString2(@ApplicationContext context: Context, @Named("String1") testString1: String) = "${context.getString(R.string.string_to_inject)} - $testString1" }
You use a parameter in ViewModel and scope of that parameter is ActivityScoped but has to be not less than ViewModelScoped. Component of InstallIn has to be the respective ViewModelComponent at least.
One more point about Dagger Hilt is that you are not able to configure it for the library project as the entry point for it always has to be the Application which is absent in the library.
Watching your videos feels like cheating :). Every time I struggle with something I always watch one of your relevant videos, and voila. Thanks a million times and more man...
Hey, is providing Glide instance with hilt a good practice too? Because in your spotify clone app you provided an adapter instance as well along with glide instance. Kinda confusing, if I only wanted to pass an arraylist to my adapter but passing the glide instance in the constructor over the adapter now requires me to provide the adapter instance with hilt as well it seems. So what's the best practice , Philipp?
you should always make glide a singleton, and therefore provide it. You don't need a provide function for the adapter if you inject stuff in the constructor and hilt knows how to create that stuff
Glide is a singleton by default and it uses the fragment argument to handle cancellation of requests. You should actually not provide it from Dagger but instead call Glide.with() where you need it.
Hey there. I get an error when trying to run the last thing you explained with the view model. When I replace the @InstallIn(ActivityComponent..) and @ActivityScoped annotations with @IntallIn(SingletoneComponent..) and @Singleton it works. I think it's because the MainModule which provides dependencies at an activity layer relies on the AppModule which provides dependencies at application level (because it's annotated as a singleton). Am I missing something?
What if im depended on a runtime thing ? E.g On my app I have a number picker. With 1 and 2. If user select 1 I want to Inject X thing, if user select 2 I want to inject Y thing. This X and Y are the same type. Type of Z. So in my viewModel (or whenever this will be used) I want only to `@Inject lateinit var test: Z`.
This video needs to be updated because the gradle dependencies that are mentioned are not correct at this time and the dependency for "hilt-lifecycle-viewmodel" isn't needed in the newer versions of the library (if it's added to your project, there will be runtime errors).
@@PhilippLackner please remove this video; it's a bit confusing when there are 2 vids but only one of them is correct tutorial and you have to specifically read the comments to realize which one to follow 🤷🏾
love this video. I have a question, what if I'm working with MVP (with Repository Pattern) and want to inject a room db instance and a retrofit instance? Do I need to inject roomdb and retrofit instances in the View, and send them as parameters to the presenter, and from presenter to the repository? thanks philipp for this tutorials, finally applying DI in my projects by watching your videos
ok, si lo haces como dices estarias rompiendo el patron MVP ya que el framework en este caso android no debe llegar al Presenter, lo que tienes que hacer ahi es hacer una abstraccion de esas dependicias a una interface y usar estas en tu repository una vez que lo hagas al crear el provide del repo creas otra clase que implemente cada una de las interfaces antes mencionada es decir una que implemente la del localDataSource(Room) y otra que implemente el remoteDataSource(Retorfit) en cada una de ellas puedes pasar el context o cualquier otra dependencia que necesites y sera esta implementacion la que le pases al repository. Si necesitas ayuda escribeme por discord: DjangoMx
What if the variable string2 was created in the activity in a scenario like from IntentExtras and we need to pass it to the ViewModel without using a ViewModel factory
When I try to inject to the activity the viewmodel like this fails to compile for this reason: Classifier 'RoutesListViewModel' does not have a companion object, and thus must be initialized here Anyone knows how to solve this?
Hi Philipp thanks for the tutorial, after watching this beginner tutorial, which playlist of yours would u recommend if I want to start practically using Dependency Injection.
Your library is nearly complete. It's missing a playlist for Dagger Hilt showing examples of various objects being injected into various logical places.
I didn't understand one thing: At 6:45 you stated that you can have it live for an Activity (by using ActivityComponent), but how do you tell it which Activity specifically?
for a strange reason I used hilt version 2.35 and it didn't work for me, then I used hilt version 2.40.5 and it worked, maybe someone has experienced the same thing
hey man, as always thanks for the great video, but i want to ask why don't u use koin for dependency injection? it is much much more simpler to use in my opinion
Helpful Videos but i have little suggestion , since we sometimes want to inject an a value like for example 2 strings , we can differenciate between using @Named("") , in one my project i did that also with qualifiers , now if both can do the same job what is the difference between them thank you ?
I love your tutorials, but this one should have started with "what is dagger-hilt". I never heard of it and the title made me think you were going to teach me :p
Over time, a few things changed in regards to dagger hilt. I made a new video in which I cover the most up to date things and also some more concepts I didn't cover in this one:
ua-cam.com/video/bbMsuI2p1DQ/v-deo.html
Also, note that ApplicationComponent has been replaced with SingletonComponent. ApplicationComponent will now cause a unresolved reference error.
Yes ! ApplicationComponent is Deprecated in new Version of Dagger then we have Instead use SIngletonComponent
thanks
@@vamsireddy7560 but how do you annotate the dependency itself if the class is a singleton and you want it to only exist at activity level?
@@yarivzip I believe that's ActivityComponent
This is really a complete video about Dagger Hilt and very easy to understand, as Philipp started to explain "if you want to inject 2 strings", you can realize that this video is better than others on UA-cam and in the same way it has enough fundamentals concepts of Hilt so you can start the implementation in your application.
Really thanks Sir 🤜🤛
Please don't ever stop making videos. Every time I watch one of your videos I get an Aha! Moment. Learning so much from you.
Android file system could be also a good candidate for "in detail" video ^^
This is an awesome video to easily understand Hilt. Even Google developers also don't teach like this. Thanks a lot, @Philipp Lackner for making this video.
I finally understand what is digger hilt after days of research...
why people dislike such amazing videos ? i think its youtube algorithim which does it automatically
This video clarified my many questions on Hilt and you have such a great skill of explaining complex things pretty simple way. Thanks again.
I wish every tutorial on UA-cam would be on this level! Too clean.
I've always thought CodingInFlow and CodingWithMitch's tutorials were good, but yours are better.
I was just reading a cheat sheet to get familiar with the annotations, then you upload this awesome video. Thanks!!!
Can you please provide me that cheat sheet please 👍
I actually love to see programming videos get 0 dislikes..
Agreed!
Why have you said that ?!?! Now a troller did dislike -_-
@@feepin2058 Two trolls.
@@taslimoseni2231 now four
@@ahmetburakilhan398 and now we actually cant see how much dislikes video got)
Thank you philip, the annotation @Named one helps me to deal with the problem with multiple BASE URL, Thankkk uuuu
Thankyou Man. Have learn too much in a single video..
Thanks for brief but complete intro to Hilt.
Thanks for making such clear and elaborative videos. Best
i come back again!! thanks phillipp
😀Actually , you give me a lot help in Android dev!!
You should be awarded
For those having trouble with ViewModel log cat:
@Module
@InstallIn(ActivityRetainedComponent ::class)
object MainModule {
// This will only live in main activity
// Cannot have @singleton that only lives as long as our activity
// Instead of @Singleton, we use activity scoped
@ActivityRetainedScoped
@Provides
@Named("String2")
// if we need to access context, say strings file, how?
// We used context as a parameter!!
// dagger hilt will also figure out which testString1 we will inject!!
fun provideTestString2(@ApplicationContext context: Context,
@Named("String1") testString1: String) =
"${context.getString(R.string.string_to_inject)} - $testString1"
}
@FightingCold Thanks, This was helpful for me, As I am using hilt dependency version 2.41.
Nice. What I need is an simple example of DI. And this is exactly what I’m looking for
Couldn't be better explained. Thanks!
man i need this video so much
Thank you very much BRO
wish you all the best❤❤❤👍👍👍
You have gained muscle 💪
Thank a lot for this Tuto Phillip .
you are a good teacher i love your way of teaching please keep it up and upload more tutorials.
Thank you, I will
You use a parameter in ViewModel and scope of that parameter is ActivityScoped but has to be not less than ViewModelScoped. Component of InstallIn has to be the respective ViewModelComponent at least.
for new version use SingletonComponent::class rather than ApplicationComponent::class
Thank you, was looking for this.
Thank you for explaining hilt in details !!!!
Thanks for such a wonderful explanation
I appreciate your efforts
Nice video. The demo and explanation makes it very easy to understand DI in android
Oh man, it exactly that I was looking for! Thank you so much!
すごく参考になりました。ありがとうございます!
Wish I can like this tutorial more than one time! You saved my days, thank you!
Glad it helped!
COOL ! Thanks for the explaination it's open my mind :) now heading back to Android Studio.
Thank you great explanation 🙏
Much needed........
Thank You sir 🙏🙏
Always welcome
Who the hell are these 5 people giving dislike to this kind of video. Great job man, keep up the good work
Thanks, will do!
Hi Philipp, can you make a video about how to read the android developer documentation and learn to help outselves? Love your vids😁
Sounds stupid but by just reading it. There is no "right way"
Tx Phil, nicely done, the pace was perfect.
One more point about Dagger Hilt is that you are not able to configure it for the library project as the entry point for it always has to be the Application which is absent in the library.
Perfect ! Your videos the best ones in all youtube bro!
Have you got same videos about Koin ?
Great explanation of a very difficult topic
Thank you so much for this amazing video.
Thank you very much for that!
You're welcome!
the best tutorial forever :) thanks, Philipp
Glad you liked it!
You should use the SingletonComponent, as ApplicationComponent doesn't exist in the new Dagger anymore.
Thank you, it help me to how implement dagger hilt in my project
Thanks, nice constructive explanation👍
Awesome explanation. Thank you.
thank you, this was a short but useful tutorial
Excellent 👍
Thanks for your amazing tutorials ❤
I really enjoyed the Dagger-Hilt 💕💕💕
Hey phillip can you put details video about supporting multiple screen in 2020 I see a lot of tutorial but none of works thanks for great videos
It would be awesome to explain and show things about scoping, regardless this is a good video coming from plain Dagger 2
Philipp looks like a gangsta in the thumbnail 😂❤️
Watching your videos feels like cheating :). Every time I struggle with something I always watch one of your relevant videos, and voila. Thanks a million times and more man...
Thanks a lot and happy cheating :D
It's helpful and awesome teaching style 👍
very nice video man thank you
Great content. Thankssss Philipp
Hey, is providing Glide instance with hilt a good practice too? Because in your spotify clone app you provided an adapter instance as well along with glide instance. Kinda confusing, if I only wanted to pass an arraylist to my adapter but passing the glide instance in the constructor over the adapter now requires me to provide the adapter instance with hilt as well it seems. So what's the best practice , Philipp?
you should always make glide a singleton, and therefore provide it. You don't need a provide function for the adapter if you inject stuff in the constructor and hilt knows how to create that stuff
Glide is a singleton by default and it uses the fragment argument to handle cancellation of requests. You should actually not provide it from Dagger but instead call Glide.with() where you need it.
that's new to me
@@PhilippLackner Just follow the source code of Glide.with
thank you both of you, you guys are amazing!
ApplicationComponent is now replaced with SingletonComponent in the new version of hilt.
Hey man thank you for the great explaining,🤩👍
You are the best !!!
Welcome back 😁
Thanks :D
@@PhilippLackner You're a legend. Godspeed
good explanation, thanks!
Thanks for the video, I will go next to the Spotify clone I think.
Injecting a variable into a ViewModel with Hilt can be done easily with just a Companion Object right? Why do we need Hilt for that...
Hey there. I get an error when trying to run the last thing you explained with the view model. When I replace the @InstallIn(ActivityComponent..) and @ActivityScoped annotations with @IntallIn(SingletoneComponent..) and @Singleton it works. I think it's because the MainModule which provides dependencies at an activity layer relies on the AppModule which provides dependencies at application level (because it's annotated as a singleton). Am I missing something?
What if im depended on a runtime thing ?
E.g
On my app I have a number picker. With 1 and 2. If user select 1 I want to Inject X thing, if user select 2 I want to inject Y thing.
This X and Y are the same type. Type of Z. So in my viewModel (or whenever this will be used) I want only to `@Inject lateinit var test: Z`.
Perfect as always
This video needs to be updated because the gradle dependencies that are mentioned are not correct at this time and the dependency for "hilt-lifecycle-viewmodel" isn't needed in the newer versions of the library (if it's added to your project, there will be runtime errors).
That's why I pinned a comment with another video 😅
@@PhilippLackner please remove this video; it's a bit confusing when there are 2 vids but only one of them is correct tutorial and you have to specifically read the comments to realize which one to follow 🤷🏾
the TestViewModel example does not work with lastest hill versions.
I am getting this error
Execution failed for task ':app:kaptDebugKotlin'.
How do I fix it?
love this video. I have a question, what if I'm working with MVP (with Repository Pattern) and want to inject a room db instance and a retrofit instance? Do I need to inject roomdb and retrofit instances in the View, and send them as parameters to the presenter, and from presenter to the repository? thanks philipp for this tutorials, finally applying DI in my projects by watching your videos
ok, si lo haces como dices estarias rompiendo el patron MVP ya que el framework en este caso android no debe llegar al Presenter, lo que tienes que hacer ahi es hacer una abstraccion de esas dependicias a una interface y usar estas en tu repository una vez que lo hagas al crear el provide del repo creas otra clase que implemente cada una de las interfaces antes mencionada es decir una que implemente la del localDataSource(Room) y otra que implemente el remoteDataSource(Retorfit) en cada una de ellas puedes pasar el context o cualquier otra dependencia que necesites y sera esta implementacion la que le pases al repository.
Si necesitas ayuda escribeme por discord: DjangoMx
@@DjangoMx suuper! trataré de hacer lo que me indicas, y si sigo perdido, te pido ayuda si es posible vale? Te agradezco mucho tu respuesta
What if the variable string2 was created in the activity in a scenario like from IntentExtras and we need to pass it to the ViewModel without using a ViewModel factory
very good
how i can create a singleton viewmodel sheard between 2 screens
When I try to inject to the activity the viewmodel like this fails to compile for this reason:
Classifier 'RoutesListViewModel' does not have a companion object, and thus must be initialized here
Anyone knows how to solve this?
Hi Philipp thanks for the tutorial, after watching this beginner tutorial, which playlist of yours would u recommend if I want to start practically using Dependency Injection.
I am want to create an android library (without Application Class, Activity and Fragment) using Hilt. Can you please help on that?
nice vid. unfortunately hilt doesnt support DI in kotlin object . or do you know how to?
Epic!
Your library is nearly complete.
It's missing a playlist for Dagger Hilt showing examples of various objects being injected into various logical places.
I didn't understand one thing: At 6:45 you stated that you can have it live for an Activity (by using ActivityComponent), but how do you tell it which Activity specifically?
Just the activity you inject it into
they have already removed ApplicationComponent😭 also viewmodel inject is deprecated
use @inject-corona-vaccine
Why don't you again start full app series?. They are so much helpful ☺️☺️☺️🙏
Why don't you build your own app with your own ideas and so on ?
thanks a lot, but in hilt module ApplicationComponent replaced with SingletonComponent
for a strange reason I used hilt version 2.35 and it didn't work for me, then I used hilt version 2.40.5 and it worked, maybe someone has experienced the same thing
Is @Singleton is same as 'object' keyword in Kotlin?
hi...can you tell me about kiosk application in android....this is more interesting...
hey man, as always thanks for the great video, but i want to ask why don't u use koin for dependency injection? it is much much more simpler to use in my opinion
Helpful Videos but i have little suggestion , since we sometimes want to inject an a value like for example 2 strings , we can differenciate between using @Named("") , in one my project i did that also with qualifiers , now if both can do the same job what is the difference between them thank you ?
hello bro thanks for video ))))))) thanks
perfect 👌
I love your tutorials, but this one should have started with "what is dagger-hilt". I never heard of it and the title made me think you were going to teach me :p
Is there a way to pass "myFragment" to the module? I used to do that in Dagger2 however I have no idea how to do it in Hilt
how can u buy video course "
make something similar for Timber too :)