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

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

  • @sfk1991
    @sfk1991 3 роки тому +6

    Totally love this series! Well played Mitch.

  • @orwakassab8326
    @orwakassab8326 3 роки тому

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

  • @staceyrichards8656
    @staceyrichards8656 3 роки тому

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

  • @owsky19
    @owsky19 3 роки тому

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

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

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

  • @mohdahmadi4562
    @mohdahmadi4562 3 роки тому

    It is a great quick lessons on the Clean Arch.

  • @moussawade5957
    @moussawade5957 3 роки тому +1

    Great !!! Thank u Mitch very nice courses 👍

  • @yogenp5763
    @yogenp5763 3 роки тому

    Thanks for the video Mitch, love 'em

  • @mehdiparsaei1867
    @mehdiparsaei1867 3 роки тому +1

    Thanks for your amazing teaching.

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

  • @MedAmineSouaiaia88
    @MedAmineSouaiaia88 3 роки тому +1

    Clear as usual ❤️

  • @speedboy93640
    @speedboy93640 2 роки тому

    Thanks, Mitch! This is great content :)

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

  • @tammamkhalaf1234
    @tammamkhalaf1234 3 роки тому

    thanks from the bottom of my heart

  • @appsdeveloper4024
    @appsdeveloper4024 3 роки тому

    Great !!! Thank u Mitch very nice courses

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

  • @mohammadmohit8063
    @mohammadmohit8063 3 роки тому

    Thank you Mitch!

  • @muhammedshahin6299
    @muhammedshahin6299 Рік тому

    Thank you so much, mitch

  • @hotellinaweb
    @hotellinaweb 3 місяці тому

    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.

  • @engmohamed6819
    @engmohamed6819 3 роки тому

    Wow always top, always awesome, big love bro

  • @creativeworld.5808
    @creativeworld.5808 2 роки тому

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

  • @AkshatKumawat
    @AkshatKumawat 3 роки тому +3

    Here is your 1st engagement ❤️

  • @terencejumba1939
    @terencejumba1939 2 роки тому

    You teach so well

  • @user-qh8zb8ri8j
    @user-qh8zb8ri8j 3 роки тому +1

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

  • @mishaeliseev
    @mishaeliseev 3 роки тому

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

  • @TheClaccclac
    @TheClaccclac 3 роки тому

    Thanks Mitch! 👌

  • @alaadeego5416
    @alaadeego5416 3 роки тому

    Great, many engagement

  • @ecemvarma4546
    @ecemvarma4546 2 роки тому

    great course!

  • @BCS_AAMIRASHRAF
    @BCS_AAMIRASHRAF 4 місяці тому

    Thanks Mitch

  • @YouGuto
    @YouGuto 3 роки тому +1

    Engagement! Thumbed Up!

  • @jojomajo
    @jojomajo 3 роки тому

    ty for everything!

  • @danyelsh874
    @danyelsh874 2 роки тому

    thanks dear mitch :)

  • @malikahellas9970
    @malikahellas9970 2 роки тому

    u did great job thanx

  • @user-ip6ng3wb5k
    @user-ip6ng3wb5k 11 місяців тому

    Thank you 🍀

  • @abdelrhmantalat9813
    @abdelrhmantalat9813 3 роки тому +1

    good work

  • @HelloBayzid
    @HelloBayzid 3 роки тому +1

    Thanks.

  • @vanosuperhero
    @vanosuperhero 2 роки тому

    Thanks!

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

  • @tom-wz5le
    @tom-wz5le 2 роки тому

    Thanks

  • @AK2000YY
    @AK2000YY 7 місяців тому

    thank you bro

  • @ehsanshadi810
    @ehsanshadi810 2 роки тому

    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.

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

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

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

  • @rafaelmonoh
    @rafaelmonoh 3 роки тому

    Nice!

  • @nurseyittursunkulov3319
    @nurseyittursunkulov3319 3 роки тому +1

    May Allah bless you, thanks. So cool explanation.

  • @alaqelabubaker
    @alaqelabubaker 2 роки тому

    you are the best

  • @fliamachado
    @fliamachado 3 роки тому

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

  • @electricalprogrammer456
    @electricalprogrammer456 2 роки тому

    🐐🐐🐐🐐

  • @johnybaby9574
    @johnybaby9574 3 роки тому

    Liked!

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

  • @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/

  • @therongovender9471
    @therongovender9471 3 роки тому

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

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

  • @abdulrahmankassem8982
    @abdulrahmankassem8982 2 роки тому

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

  • @gamesforu6619
    @gamesforu6619 3 роки тому

    Can I provide instance of interface with Hilt?

  • @bboydarknesz
    @bboydarknesz 3 роки тому

    here my engetment.
    cheerssss

  • @anuradhaamarasinghe9649
    @anuradhaamarasinghe9649 2 роки тому

    Yep Engaged!

  • @ChrisAthanas
    @ChrisAthanas 3 роки тому

    Engine engaged

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

  • @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 :)

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

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

  • @JitubhaiyaPhysics
    @JitubhaiyaPhysics 3 роки тому +1

    mitch

  • @aydogdyaydogdiev1255
    @aydogdyaydogdiev1255 2 роки тому

    engagement

  • @truphenalwanga9829
    @truphenalwanga9829 3 роки тому

    Here's some randomEngagement!

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

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