Dagger 2 Android Tutorial - Implementing Dagger Dependency Injection

Поделиться
HTML-код
  • Опубликовано: 24 янв 2025

Комментарии • 32

  • @artmcgee4941
    @artmcgee4941 11 месяцев назад +1

    Thanks you for your content. You should consider placement of yourself in the video as it blocks needed info and can create problems with people following along.

    • @SimplifiedCoding
      @SimplifiedCoding  11 месяцев назад

      Yeah, thats why I am not putting my face in new videos.

  • @jaysonlights6342
    @jaysonlights6342 3 года назад

    just want to leave a comment of appreciation.. im learning a lot from your videos.. please continue to your good work sir.. more power 😁 👍

  • @vaibhavalone4720
    @vaibhavalone4720 Год назад +1

    What code you have written in BaseApi which extends in AuthApi interface? I have one suggestion if you don't mind. You are very good instructor thanks for taking saperate example for each concept. But before starting the tutorial can you go through all files inside java package? so that everyone will understand the code in each file. Because after long time the code is not available on server. Thanks.

  • @mojeebhasan5283
    @mojeebhasan5283 3 года назад

    fun provideAuthRepository(remoteDataSource : RemoteDataSource) : AuthRepository{
    return(AuthRepository(remoteDataSource.buildApi(AuthApi::class.java),context),UserPrefences(context))
    }
    will this code work or not. I did so because AuthRepository also can't be constructor injected and AuthRepository can't be constructor injected because
    it has two constructor parameter AutApi and UserPrefences).

  • @ChrisAthanas
    @ChrisAthanas 3 года назад +13

    Functionality needs to be explained not just syntax
    Honestly I’m more confused now

    • @SimplifiedCoding
      @SimplifiedCoding  3 года назад +3

      Its very simple, you should watch it from the first video.
      Check here: bit.ly/3sy0Ghp
      I would like to give you the basic idea.
      Dagger's goal here is to provide dependency. And first we will try to constructor inject everything.
      So if a class is annotated with @Inject, that means dagger can provide it's instance. The condition is all the if there are any class in the constructor parameter, those classes should also have @Inject because dagger needs to know how to build it.
      for example.
      class A @Inject constructor(b: B)
      B should also have @Inject
      class B @Inject constructor()
      Once your classes satisfy this condition, you can inject them using @Inject.
      For example in an Activity you can write
      @Inject lateinit var a: A;
      This is how we inject dependencies. And when we call the function inject() from AndroidInjection all the variables annotated with @Inject are injected.
      Now another thing to note is, it is not always possible to write @Inject in constructor. What if the class you want is from a library or it is an interface. You cannot write @Inject in constructor then.
      For this case you can create a Module, that will tell dagger how to provide these instances.
      I hope you understood. Thanks

    • @ChrisAthanas
      @ChrisAthanas 3 года назад

      @@SimplifiedCoding I know you keep saying it’s very simple but honestly it’s not, it’s one of the most complex and confusing topics on Android. It’s a series of hacks and workarounds that requires you to fully and intimately understand the Andriod way of handling things. The whole system is in need of scrapping and starting over due to the numerous workarounds and bug fixes and patches. Andriod is definitely showing its age with the level of complexity needed to just do very simple things like provide an object in a scope. We are attempting to do things that the platform was never designed to do and it’s so messy and confusing that nearly everyone gets it wrong.
      Thank you for the enhanced explanation, and I do understand the basics but the advanced topics are very confusing.

    • @SimplifiedCoding
      @SimplifiedCoding  3 года назад +1

      I understand your feeling. 😄 But things are getting simpler. Have you checked the next video that is about hilt?

    • @ChrisAthanas
      @ChrisAthanas 3 года назад

      @@SimplifiedCoding yes, ive been studying hilt for a couple of months and Hilt is definitely an improvement over Dagger as far as understandability and comprehension is concerned. It does have limitations for creating a multi-moduile (not dagger modules, but Android modules). You must still use Dagger if you want to make your app modular... its also very confusing the overloading of these terms in the same domain... I'm sure all this confusion and complexity has made budding Android developers quit and move on to flutter or React or iOS! :)

  • @jafajarvis324
    @jafajarvis324 3 года назад +4

    Can we use dagger hilt instead of using dagger2? I think that dagger hilt is very easy to implement. Am i wrong?

    • @SimplifiedCoding
      @SimplifiedCoding  3 года назад +2

      Yes, hilt is easy. Just wait for the next video.

    • @jafajarvis324
      @jafajarvis324 3 года назад +1

      Ya am eagerly waiting for your every video. Thanks for the tutorial. :)

  • @saurabhsingh1608
    @saurabhsingh1608 3 года назад

    I like the way we get to know the dagger impl in while real project scenario impl ....it gives a real hands-on on live projects alot . Keep going. Later if u could also make bdd testcase vedio that would be helpful... replacing UI testcases

  • @ManishPatel3030
    @ManishPatel3030 3 года назад +1

    I like this series. 👏

  • @RajSharma-lt3fw
    @RajSharma-lt3fw 3 года назад

    Hey mate, the gihub link for this project seems to be incorrect, also there is just one branch (master), which is an implementation of Dagger Hilt. Can you update the branches for this video ? Thanks

  • @sajjadaria1890
    @sajjadaria1890 3 года назад

    Hi belalkhan , why you are not using scrcpy for showing your screen phone? That's very cool , i hope helping you ! Good luck

  • @Joe123Jackol
    @Joe123Jackol 2 года назад

    Can somebody explain to me why I cannot define "DaggerAppComponent" inside my Application class

  • @rohitjakhar6672
    @rohitjakhar6672 3 года назад +2

    Why you cant use hilt that is very easy
    I use HIlt and now it seem very hard

    • @SimplifiedCoding
      @SimplifiedCoding  3 года назад +2

      When did I say I cannot use hilt? 🤔🤔
      Next video will be about Hilt. This course is about dependency Injection from scratch.
      Here I am covering from manual dependency injection to dagger to hilt.
      So that you get to know everything. ✌️

    • @rohitjakhar6672
      @rohitjakhar6672 3 года назад +1

      @@SimplifiedCoding i mean dagger is so hard and thats why this video very confusing
      I am waiting for hilt

    • @SimplifiedCoding
      @SimplifiedCoding  3 года назад

      Next and the last video of this course is about hilt. ✌️ cheers

  • @nirmalrevar
    @nirmalrevar 3 года назад +1

    very nice video.

  • @rushidesai2836
    @rushidesai2836 3 года назад +2

    Why not Hilt?

  • @pejmanazad5852
    @pejmanazad5852 3 года назад

    Is there still a reason to use Dagger instead of HILT in new projects?

  • @johndoan3526
    @johndoan3526 2 года назад

    Oustanding!

  • @tabishkhan2012
    @tabishkhan2012 2 года назад

    In which company you are working ?

  • @eluroalex5920
    @eluroalex5920 3 года назад +1

    Lol... Thank goodness we don't have to use Dagger2 anymore