Hilt - Providing Retrofit Instance and Repository
Вставка
- Опубліковано 16 гру 2020
- The BEST android courses in the world: codingwithmitch.com/
In this video I show two different ways to provide objects as dependencies using Hilt. We use the Provides annotation and the Inject annotation. The Retrofit instance is injecting into the repository and the repository is injected into the viewmodel.
Code: github.com/mitchtabian/MVVMRe...
Follow me:
Instagram: / codingwithmitch
Twitter: / mitch_tabian
.
. - Наука та технологія
Finally I can understand the power of Dependency Injection! With Google's docs I was struggling understanding the Why, now I don't
I am watching from like 4 hours straight into this tutorial ..but still wants to learn and watch more of the mitch tutorials..What an engagement Capabilty mitch and his style of teaching is ..very few can do it ..HatsOff.
Totally love this series! Well played Mitch.
There is nothing like your videos, thanks for your great efforts to make them.
Once again, very clear and easy to follow. You make learning Android development a pleasure. Many thanks.
I don't think I've ever seen a UA-cam video with 0 dislikes. Totally deserved, thank you for the free course Mitch!
This stuff is easy to understand when it is explained by you Mitch. It still boggles the mind how those people created Dagger and Hilt, they must be so freaking brainy it's unreal!!
Amazing course, really helpful !
Thanks a lot man !!
Hi sir, I am learning a lot from your course, your teaching skill is just awesome!! Just one point I want to suggest, if you can put the same sequence no. as thumbnail on video title also, then it would be really helpful, as we can't see thumbnail while video playing, we can't know which is current number (and so, which is next).
Once again, thanks a very much for this super awesome series.
It is a great quick lessons on the Clean Arch.
Great !!! Thank u Mitch very nice courses 👍
Thanks for the video Mitch, love 'em
Thanks for your amazing teaching.
thanks for this series Mitch!
I always confuse with @inject in repository. I thought it has the same function as @viewModelInject/@AndroidEntryPoint or @Inject as in field injection in activity since we passed something in the repository constructor. But turns out it is used to provides the instance of repository. So for me using module and @Provides makes the code clearer to read
Clear as usual ❤️
Thanks, Mitch! This is great content :)
Android Guide says use @Binds over @Provides to create an implementation of an interface.
Also they say use constructor injection whenever possible.
Also they say use Qualifiers over @Named.
thanks from the bottom of my heart
Great !!! Thank u Mitch very nice courses
Here's your engage. Yay i got the answer for how hilt resolves dependency of same data types. @Named comes to the rescue. Thank you very much!!
Thank you Mitch!
Thank you so much, mitch
Good video on how to use Hilt.
I still struggle to understand why we should use it. It looks like there is a bunch of philosophers who want to make us crazy.
I do grasp all principles of SOLID programming.
Regarding dependency injection now.
Do we want to change database on the fly?
Do we want to change DAO on the fly?
If I can suggest please make a new video solely on why using dependency injection, as I see a lot of fanatics of this framework/pattern out there but I really do not comprehend its utility.
Wow always top, always awesome, big love bro
great sir you are genius. hats off for my dear sir mitch.
Here is your 1st engagement ❤️
You teach so well
you can simply add the token in okhttp interceptor as retrofit client instead of passing it everytime
Like ! Thank you, Mick! I think I started to understand Hilt :)
Mitch )))
Thanks Mitch! 👌
Great, many engagement
great course!
Thanks Mitch
Engagement! Thumbed Up!
ty for everything!
thanks dear mitch :)
u did great job thanx
Thank you 🍀
good work
Thanks.
Thanks!
Such a great video. One question: You annotated repository with @Singleton, and then injected it in Viewmodel.When viewmodel is cleared, is the repository that contain Retrofit instance will be cleared as well? isn't it will show up a memory leaks?
Thanks
thank you bro
It was a great idea that you preferred using modules instead of @Inject annotation.
I suppose it will be also helpful for injecting classes in Kotlin multi platform since iOS must have a different DI library. I'm just guessing. I haven't worked with KMP yet.
Awesome video!! I've seen almost all of them now ahaha Is there a way to Inject something in a class that's not from the Android framwork?? not an activity, fragment, etc. But just a plain class
It's really awesome but i have one question how to pass the bundle data of fragment into viewmodel constructor.
Thanks for all your work.
One note: I would use constructor with @Inject annotation whenever possible and @Provides annotation for third-party dependencies which source code is not available for modifications.
Ya that's fine. I prefer using provides so everything is in one place and I can replace modules for fakes
Great tutorial as always, really appreciate you sharing your knowledge. I wanted to ask as part of the Jetpack Compose series, if you can do a tutorial on Room, Pager 3: PagingSource and RemoteMediator.
Room will be in the next course. Probably not the paging libraries they always disappoint
@@codingwithmitch Can't wait, for Room in the next course that will be nice, but what do you mean when you say, they always disappoint?
@@Shoan3D I don't like the paging libraries. I always end up building a custom system
@@codingwithmitch Thank you for taking time to do the free videos and more time to actually reply to comments. I can only imagine the amount to work you are putting into this.
I'm pretty new to Android development. I thought it would be a lot of work to build a custom system that offers the same functionality. So I will really appreciate it when you find time to do it.
I think I understand why you might not like the Paging libraries. Hopefully Pager 3 makes a difference, fingers crossed 🤞. Thanks again 👍 Mitch, great work!!
Thanks Mitch, love the series. Can you please tell me why your repository is a singleton ? So you plan to use a single repository for the whole app ? I don’t see how it can scale that way...
It is a single instance of the repository. You wouldn't want each reference to the repository in every constructor to launch a new repository each time it is called.
Nice!
May Allah bless you, thanks. So cool explanation.
you are the best
Hi Mitch, one question : Can I field inject in ViewModels ? or I only can use @ViewModelInject in the constructor ?
🐐🐐🐐🐐
Liked!
Hey Mitch, I have a question about scoping of injected Use Cases. For a UseCaseModule or InteractorsModule (as you call it in your Dagger-Hilt-Playground GitHub project), I see that you've used the ApplicationComponent. However, I've seen another Hilt tutorial, where the guy chose to install it in the ActivityRetainedComponent (where he also installed his RepositoryModule). I feel like having these elements as Singletons, like you do, makes the most sense, but can you maybe help explain the reasoning of doing so?
PS. I know that injection of Use Cases might come up in the next course, as you've mentioned previously, but I am currently working on a project where I want to use clean architecture and Jetpack / Android X libraries as much as possible, so figured I would try and ask.
Probably ActivityRetainedComponent is better. You don't need your use cases living longer than the viewmodel they are injected into.
@@codingwithmitch cool, thanks. And for RepositoryModule, I guess sticking to Singleton makes most sense, in order to enforce "single source of truth", so you would never be interested in creating several instances of the same repository? That's what makes sense to me, but only asking because I saw this other guy install his RepositoryModule in ActivityRetainedComponent.
@@emil_fa repository is treated the same as use cases. So activity retained component makes sense also
Hello Mitch, can you make more videos about MVI CRUD using Kotlin?
Entire course right here man codingwithmitch.com/courses/android-clean-architecture/
Hi, why don't you prefix your interface with an I, for example IRepositoryService
9:55 does this also works on Dagger 2 cause I just tried it to inject in use case constructor it says that the repository class cannot be provided without an @Provides-annotated method
if the token changed and the framgent is running, how can I update the token value or refresh it
Can I provide instance of interface with Hilt?
here my engetment.
cheerssss
Yep Engaged!
Engine engaged
I have ViewModel and Repository , i',m use @inject field not @inject constructor and have error null variable injected in both , can you explain for me ? I have module and installed in app
fyi ApplicationComponent is Deprecated in Dagger Version 2.30
ApplicationComponent removed in Dagger Version 2.31
Alternatively SingletonComponent should be used instead of ApplicationComponent :)
I thought we should only use @Provides when we do not have access to the constructor. It's like third-party libraries.
If you want to use @Inject on the constructor instead then go ahead
actually I believe method 1 and 2 are not the same. in method 2 you are adding the implementation to the graph and not the interface. you would need an addition Binds in a module for method 2. Correct me if I am wrong.
I messed up in android studio can you do a video on how to ""RESET ANDROID STUDIO TO DEFAULT SETTING " PLZ PLZZZZ if anyone knows plz comment down
Uninstall? 😵
mitch
Jit
engagement
Here's some randomEngagement!
I fucked up in android studio can you do a video on how to ""RESET ANDROID STUDIO TO DEFAULT SETTING " PLZ PLZZZZ if anyone knows plz comment down
Good explanation, but you spend mostly explaining all Dagger stuffs, nothing specific to what's new in Hilt. Video title is kind of misleading.
Hi Mitch, you are a good programmer, but when it comes to teaching you do not explain the video from the beginning, writing code in your videos is taken from the middle of the program, not from 0, the result is ambiguity, please try a simple explanation, for example codinginflow
low
brother I think you're not following him from the beginning of the series 😑
This is part 15 of the course
@@AkshatKumawat yep probably not
Thanks!