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
    .
    .
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 98

  • @simonesummo4433
    @simonesummo4433 2 ปีที่แล้ว +1

    Finally I can understand the power of Dependency Injection! With Google's docs I was struggling understanding the Why, now I don't

  • @sfk1991
    @sfk1991 3 ปีที่แล้ว +6

    Totally love this series! Well played Mitch.

  • @talhashaikh1435
    @talhashaikh1435 2 ปีที่แล้ว +1

    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.

  • @orwakassab8326
    @orwakassab8326 3 ปีที่แล้ว

    There is nothing like your videos, thanks for your great efforts to make them.

  • @owsky19
    @owsky19 3 ปีที่แล้ว

    I don't think I've ever seen a TH-cam video with 0 dislikes. Totally deserved, thank you for the free course Mitch!

  • @staceyrichards8656
    @staceyrichards8656 3 ปีที่แล้ว

    Once again, very clear and easy to follow. You make learning Android development a pleasure. Many thanks.

  • @hellespont5072
    @hellespont5072 3 ปีที่แล้ว

    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!!

  • @_ashishpandey
    @_ashishpandey 2 ปีที่แล้ว +1

    Amazing course, really helpful !
    Thanks a lot man !!

  • @moussawade5957
    @moussawade5957 3 ปีที่แล้ว +1

    Great !!! Thank u Mitch very nice courses 👍

  • @yogenp5763
    @yogenp5763 3 ปีที่แล้ว

    Thanks for the video Mitch, love 'em

  • @MedAmineSouaiaia88
    @MedAmineSouaiaia88 3 ปีที่แล้ว +1

    Clear as usual ❤️

  • @speedboy93640
    @speedboy93640 3 ปีที่แล้ว

    Thanks, Mitch! This is great content :)

  • @mohdahmadi4562
    @mohdahmadi4562 3 ปีที่แล้ว

    It is a great quick lessons on the Clean Arch.

  • @mehdiparsaei1867
    @mehdiparsaei1867 3 ปีที่แล้ว +1

    Thanks for your amazing teaching.

  • @vengateshm2122
    @vengateshm2122 3 ปีที่แล้ว

    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!!

  • @appsdeveloper4024
    @appsdeveloper4024 3 ปีที่แล้ว

    Great !!! Thank u Mitch very nice courses

  • @VikramsinhChampavat
    @VikramsinhChampavat 2 ปีที่แล้ว +3

    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.

  • @mohammadmohit8063
    @mohammadmohit8063 3 ปีที่แล้ว

    Thank you Mitch!

  • @muhammedshahin6299
    @muhammedshahin6299 ปีที่แล้ว

    Thank you so much, mitch

  • @tammamkhalaf1234
    @tammamkhalaf1234 3 ปีที่แล้ว

    thanks from the bottom of my heart

  • @RifqiMukhtar
    @RifqiMukhtar 3 ปีที่แล้ว

    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

  • @engmohamed6819
    @engmohamed6819 3 ปีที่แล้ว

    Wow always top, always awesome, big love bro

  • @ecemvarma4546
    @ecemvarma4546 3 ปีที่แล้ว

    great course!

  • @mishaeliseev
    @mishaeliseev 3 ปีที่แล้ว

    Like ! Thank you, Mick! I think I started to understand Hilt :)

  • @AkshatKumawat
    @AkshatKumawat 3 ปีที่แล้ว +3

    Here is your 1st engagement ❤️

  • @creativeworld.5808
    @creativeworld.5808 2 ปีที่แล้ว

    great sir you are genius. hats off for my dear sir mitch.

  • @TheClaccclac
    @TheClaccclac 3 ปีที่แล้ว

    Thanks Mitch! 👌

  • @hotellinaweb
    @hotellinaweb 4 หลายเดือนก่อน

    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.

  • @YouGuto
    @YouGuto 3 ปีที่แล้ว +1

    Engagement! Thumbed Up!

  • @terencejumba1939
    @terencejumba1939 2 ปีที่แล้ว

    You teach so well

  • @alaadeego5416
    @alaadeego5416 3 ปีที่แล้ว

    Great, many engagement

  • @abdelrhmantalat9813
    @abdelrhmantalat9813 3 ปีที่แล้ว +1

    good work

  • @malikahellas9970
    @malikahellas9970 2 ปีที่แล้ว

    u did great job thanx

  • @danyelsh874
    @danyelsh874 2 ปีที่แล้ว

    thanks dear mitch :)

  • @jojomajo
    @jojomajo 3 ปีที่แล้ว

    ty for everything!

  • @BCS_AAMIRASHRAF
    @BCS_AAMIRASHRAF 5 หลายเดือนก่อน

    Thanks Mitch

  • @user-ip6ng3wb5k
    @user-ip6ng3wb5k ปีที่แล้ว

    Thank you 🍀

  • @rafaelmonoh
    @rafaelmonoh 3 ปีที่แล้ว

    Nice!

  • @alaqelabubaker
    @alaqelabubaker 2 ปีที่แล้ว

    you are the best

  • @vanosuperhero
    @vanosuperhero 2 ปีที่แล้ว

    Thanks!

  • @AK2000YY
    @AK2000YY 8 หลายเดือนก่อน

    thank you bro

  • @sleepydev4700
    @sleepydev4700 3 ปีที่แล้ว +1

    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?

  • @johnybaby9574
    @johnybaby9574 3 ปีที่แล้ว

    Liked!

  • @HelloBayzid
    @HelloBayzid 3 ปีที่แล้ว +1

    Thanks.

  • @veys7035
    @veys7035 3 ปีที่แล้ว +1

    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.

  • @nurseyittursunkulov3319
    @nurseyittursunkulov3319 3 ปีที่แล้ว +1

    May Allah bless you, thanks. So cool explanation.

  • @fliamachado
    @fliamachado 3 ปีที่แล้ว

    Hi Mitch, one question : Can I field inject in ViewModels ? or I only can use @ViewModelInject in the constructor ?

  • @tom-wz5le
    @tom-wz5le 2 ปีที่แล้ว

    Thanks

  • @electricalprogrammer456
    @electricalprogrammer456 2 ปีที่แล้ว

    🐐🐐🐐🐐

  • @quewealawea
    @quewealawea 3 ปีที่แล้ว

    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

  • @ehsanshadi810
    @ehsanshadi810 3 ปีที่แล้ว

    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.

  • @bitwisedevs469
    @bitwisedevs469 2 ปีที่แล้ว

    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

  • @user-qh8zb8ri8j
    @user-qh8zb8ri8j 3 ปีที่แล้ว +1

    you can simply add the token in okhttp interceptor as retrofit client instead of passing it everytime

  • @Shoan3D
    @Shoan3D 3 ปีที่แล้ว

    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.

    • @codingwithmitch
      @codingwithmitch  3 ปีที่แล้ว +1

      Room will be in the next course. Probably not the paging libraries they always disappoint

    • @Shoan3D
      @Shoan3D 3 ปีที่แล้ว

      @@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?

    • @codingwithmitch
      @codingwithmitch  3 ปีที่แล้ว +1

      @@Shoan3D I don't like the paging libraries. I always end up building a custom system

    • @Shoan3D
      @Shoan3D 3 ปีที่แล้ว

      @@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!!

  • @salsayist
    @salsayist 3 ปีที่แล้ว

    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...

    • @Girrafffe
      @Girrafffe 3 ปีที่แล้ว +1

      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.

  • @roshanbhagat6768
    @roshanbhagat6768 3 ปีที่แล้ว

    It's really awesome but i have one question how to pass the bundle data of fragment into viewmodel constructor.

  • @Mr4eS
    @Mr4eS 3 ปีที่แล้ว

    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.

    • @codingwithmitch
      @codingwithmitch  3 ปีที่แล้ว

      Ya that's fine. I prefer using provides so everything is in one place and I can replace modules for fakes

  • @abdulrahmankassem8982
    @abdulrahmankassem8982 2 ปีที่แล้ว

    if the token changed and the framgent is running, how can I update the token value or refresh it

  • @longnguyenuc8205
    @longnguyenuc8205 3 ปีที่แล้ว

    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

  • @emil_fa
    @emil_fa 3 ปีที่แล้ว

    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.

    • @codingwithmitch
      @codingwithmitch  3 ปีที่แล้ว +1

      Probably ActivityRetainedComponent is better. You don't need your use cases living longer than the viewmodel they are injected into.

    • @emil_fa
      @emil_fa 3 ปีที่แล้ว

      @@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.

    • @codingwithmitch
      @codingwithmitch  3 ปีที่แล้ว +1

      @@emil_fa repository is treated the same as use cases. So activity retained component makes sense also

  • @therongovender9471
    @therongovender9471 3 ปีที่แล้ว

    Hi, why don't you prefix your interface with an I, for example IRepositoryService

  • @gamesforu6619
    @gamesforu6619 3 ปีที่แล้ว

    Can I provide instance of interface with Hilt?

  • @bboydarknesz
    @bboydarknesz 3 ปีที่แล้ว

    here my engetment.
    cheerssss

  • @juniorlapunete4660
    @juniorlapunete4660 3 ปีที่แล้ว

    Hello Mitch, can you make more videos about MVI CRUD using Kotlin?

    • @codingwithmitch
      @codingwithmitch  3 ปีที่แล้ว

      Entire course right here man codingwithmitch.com/courses/android-clean-architecture/

  • @JitubhaiyaPhysics
    @JitubhaiyaPhysics 3 ปีที่แล้ว +1

    mitch

  • @mehdiparsaei1867
    @mehdiparsaei1867 3 ปีที่แล้ว +1

    I thought we should only use @Provides when we do not have access to the constructor. It's like third-party libraries.

    • @codingwithmitch
      @codingwithmitch  3 ปีที่แล้ว +1

      If you want to use @Inject on the constructor instead then go ahead

  • @ChrisAthanas
    @ChrisAthanas 3 ปีที่แล้ว

    Engine engaged

  • @iD0ntWannaGr0wUp
    @iD0ntWannaGr0wUp 3 ปีที่แล้ว

    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.

  • @Mohit-gb9dv
    @Mohit-gb9dv 3 ปีที่แล้ว +1

    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

  • @tomrowbotham4369
    @tomrowbotham4369 2 ปีที่แล้ว

    fyi ApplicationComponent is Deprecated in Dagger Version 2.30
    ApplicationComponent removed in Dagger Version 2.31
    Alternatively SingletonComponent should be used instead of ApplicationComponent :)

  • @anuradhaamarasinghe9649
    @anuradhaamarasinghe9649 2 ปีที่แล้ว

    Yep Engaged!

  • @Mohit-gb9dv
    @Mohit-gb9dv 3 ปีที่แล้ว +1

    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

  • @truphenalwanga9829
    @truphenalwanga9829 3 ปีที่แล้ว

    Here's some randomEngagement!

  • @aydogdyaydogdiev1255
    @aydogdyaydogdiev1255 2 ปีที่แล้ว

    engagement

  • @karthikperiasami
    @karthikperiasami 2 ปีที่แล้ว

    Good explanation, but you spend mostly explaining all Dagger stuffs, nothing specific to what's new in Hilt. Video title is kind of misleading.

  • @fourcade7851
    @fourcade7851 3 ปีที่แล้ว +2

    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

    • @AkshatKumawat
      @AkshatKumawat 3 ปีที่แล้ว

      brother I think you're not following him from the beginning of the series 😑

    • @codingwithmitch
      @codingwithmitch  3 ปีที่แล้ว

      This is part 15 of the course

    • @codingwithmitch
      @codingwithmitch  3 ปีที่แล้ว +1

      ​@@AkshatKumawat yep probably not

  • @dmitrykroytor8232
    @dmitrykroytor8232 2 ปีที่แล้ว

    Thanks!