Full Guide to Manual Dependency Injection + Removing Dagger

Поделиться
HTML-код
  • Опубликовано: 29 авг 2023
  • In this video you'll learn how you can get rid of Dagger-Hilt and start manually injecting your dependencies to have the same advantages while minimizing build time and errors.
    Secure your EARLY BIRD discount for my new testing course bundle! (just a few more days)
    pl-coding.com/testing
    Initial branch with Dagger:
    github.com/philipplackner/Man...
    Final branch with manual DI:
    github.com/philipplackner/Man...

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

  • @PhilippLackner
    @PhilippLackner  9 месяцев назад +81

    Some clarification:
    I'm neither against Dagger nor completely pro manual DI. In most more complex projects Dagger provides functionality you can't easily achieve with manual DI. But in simpler projects, it's overkill in most cases.
    The main thing I want to show with this is that DI on Android != Dagger. DI is often overcomplicated and people think it can only be achieved with Dagger which is simply not true.

    • @houssemzaier
      @houssemzaier 9 месяцев назад +4

      Now I agree 👍 good clarification

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад

      My question is how are these singletons released after they go out of scope and no longer necessary?

    • @paulsoja2732
      @paulsoja2732 9 месяцев назад

      And what about scopes?

    • @houssemzaier
      @houssemzaier 9 месяцев назад

      @@paulsoja2732 this when manual DI fails

    • @houssemzaier
      @houssemzaier 9 месяцев назад

      @@ChrisAthanas a jvm singleton is never released

  • @ErdemKalyoncu
    @ErdemKalyoncu 9 месяцев назад +26

    I think learning Manual DI helps you understand what is going on under the hood when you use Hilt or Koin. Very helpful video as usual. Thank you!

  • @hesham4744
    @hesham4744 9 месяцев назад +4

    Thank you so much for this insightful video! I was really struggling to wrap my head around Dagger and its complexities. Your video brilliantly showcases alternative ways to achieve manual dependency injection on Android, offering a fresh perspective and a sense of relief. Your clear explanations and demonstrations have made the concept crystal clear, and I'm now more confident in navigating these challenges. Your effort in simplifying this topic is truly appreciated. Keep up the great work!

  • @skarloti
    @skarloti 9 месяцев назад +5

    I haven't seen such a useful and well explained solution in a long time. I think most Android developers will use this approach because everything is visible and clear. For small projects written in pure Kotlin, I think it is unnecessary to use Dagger/Hilt. Thank you so much!

  • @watermelon0guy
    @watermelon0guy 9 месяцев назад +8

    Thanks for video! I didn't understand why everyone was constantly using Dagger (or Hilt). After all, for small projects it would be more efficient to do it manually. This video shows where to start and how to build architecture

    • @rcgonzalezf
      @rcgonzalezf 9 месяцев назад +1

      For small projects build time isn't an issue, so I don't know what we're optimizing here. With Dagger+Hilt the video would have ended in minute 2, all the other 10 minutes was due to manually injecting the objects.

    • @torstenflammiger8444
      @torstenflammiger8444 9 месяцев назад

      It's about learning and understanding how things work@@rcgonzalezf

  • @mark-147
    @mark-147 9 месяцев назад +5

    Good video. As mentioned, there are some cases where third party DI makes sense. Multi module apps for example, where most modules don't have access to the Application subclass.

  • @FabioSangregorio-od4qv
    @FabioSangregorio-od4qv 9 месяцев назад

    Ths simple approach works also for other languages and contexts, I'll be using it! Thanks!

  • @jenovas00
    @jenovas00 9 месяцев назад +25

    No do not move backwards :D
    Use Dagger + Hilt if you know how to use it. It just makes your life so much easier in every possible way.
    Manual Dependency is actually more complicated than Dagger + Hilt at this time.
    Dagger + Hilt allows you to easily inject into Activity, Fragment, Compose, ViewModel, Workers, View, Service, BroadcastReceivers, Alarms, Tests, where you'd need custom factories / implementations / huge singletons or god classes to do it manually.

    • @PhilippLackner
      @PhilippLackner  9 месяцев назад +23

      While I agree that using Dagger has some advantages over manual DI, I think it by no means belongs in every project out there. Most people think you have to use Dagger in order to achieve DI and forget about what DI is really about

    • @ShaqarudenGames
      @ShaqarudenGames 9 месяцев назад +8

      Koin

    • @ShaqarudenGames
      @ShaqarudenGames 9 месяцев назад +1

      Honestly though don’t be completely shutout from any other solution. Dagger is not the only way to do it

    • @marekgajda838
      @marekgajda838 9 месяцев назад +5

      Well, Koin is runtime di, just for this reason my choice is dagger/hilt

    • @leslied7456
      @leslied7456 9 месяцев назад +1

      I think it depends. It’s even more complicated for tiny projects, modules and features.

  • @mohamedalaa6yahoo
    @mohamedalaa6yahoo 4 месяца назад

    I liked the way you use companion object cause I always run in problem of needing a singletone with a constructor, New great idea THANKS BRO 😄

  • @vitalijuskolinko9011
    @vitalijuskolinko9011 9 месяцев назад +3

    Got used to Dagger 2 / Dagger Hilt :) This manual DI also great! I'd rather say that it is very useful for beginners to understand how Dagger works under the hood ;)
    🇱🇹

  • @tch.777
    @tch.777 9 месяцев назад

    Thank you Philipp you are the best 🙏🔥

  • @GabrielTrifa
    @GabrielTrifa 4 месяца назад

    i really enjoy your videos. thanks!

  • @JazzyJesterTechPing
    @JazzyJesterTechPing 9 месяцев назад

    Thanks, nice approach !

  • @MMateos97
    @MMateos97 9 месяцев назад +1

    The best Android related videos on RUclips 👌

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад +1

      Philip shows the google android team how to explain their goofy technology so people outside the company can understand

  • @serlok4688
    @serlok4688 9 месяцев назад +2

    Hello Philip, would you consider selling the course prices more affordable in countries like turkey as steam does? I want to take your courses but as a student it is quite difficult for me to afford.

  • @ojo_lali_ngaji
    @ojo_lali_ngaji 9 месяцев назад

    always make usefull content 🤝

  • @MegaAntarioGames
    @MegaAntarioGames 9 месяцев назад +1

    Seems like a good way to add DI to a KMM project.

  • @ibrahimanimasahun9431
    @ibrahimanimasahun9431 9 месяцев назад +4

    Dagger/Hilt worshippers keeps saying you're reinventing the wheel, not knowing this is actually the wheel that was reinvented

    • @PhilippLackner
      @PhilippLackner  9 месяцев назад

      😂

    • @vibovitold
      @vibovitold 9 месяцев назад

      That's about as true as saying that a modern car wheel with TPMS sensors, self-healing tires and carbon fiber is a "reinvention" of the original stone age wheel.

  • @alexteodorovici_yt
    @alexteodorovici_yt 9 месяцев назад

    Awesome, thank you 😀

  • @mfs6376
    @mfs6376 7 месяцев назад

    Thanks for this, it was really helpful but I have a query regarding this. How to use app module to inject dependency that are async like room database. The problem is this I have used the same code for this but as soon I access that database from AppModule in my view model it throws null pointer exception. Any suggestions for that?

  • @martinseal1987
    @martinseal1987 9 месяцев назад +1

    Would have been nice to speak about singletons and factories in this

  • @ahmadrezasariaslani4650
    @ahmadrezasariaslani4650 9 месяцев назад

    Nice video! How does the create() method in retrofit know it should return AuthApi? How does it read the return type of the enclosed function?

    • @PhilippLackner
      @PhilippLackner  9 месяцев назад

      The type is specified by the function return type

  • @mohamadrezamehrjou9553
    @mohamadrezamehrjou9553 8 месяцев назад

    Great video thank you Philipp

  • @bungholici-gg5vt
    @bungholici-gg5vt 9 месяцев назад

    What about objects that should survive a configuration change, but should not be singletons? Use some class container with onRetainNonConfigurationInstance?

  • @wigs_n_roses
    @wigs_n_roses 9 месяцев назад

    Hi, Philipp! A question about your Testing course: in UI testing module do you explain how to test Compose UI or only traditional views?
    Thank you for the answer in advance! ❤

    • @PhilippLackner
      @PhilippLackner  9 месяцев назад +1

      It's all focused on compose 💪🏻

    • @wigs_n_roses
      @wigs_n_roses 9 месяцев назад

      @@PhilippLackner great, than I will buy!

  • @berkowk
    @berkowk 2 месяца назад

    Even better would be to access an application instance in the create method which accepts extras. This way we may move context-dependent dependencies provider to application (non companion). While the ViewModel.Factory instance could be declared as a stateless object.

  • @senk0n
    @senk0n 9 месяцев назад +1

    what a timing, just before alpha KSP support for dagger released :D

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад

      Annotations are so confusing and messy

  • @yosipipi
    @yosipipi 9 месяцев назад +1

    Cool idea for a video! Also nice, for better understanding of what happens behind the scenes. Whether to really use this approach, maybe if the projcet is really small. Because once you've got more things to Inject, like 10 useCases for your viewmodel, you wouldn't want to do so every time you refer to that viewmodel. It's also not good for seperation of concerns, because it's not the screen's/activity's business what use case its viewmodel is using...
    But nice idea ;)

  • @denisgithuku8563
    @denisgithuku8563 9 месяцев назад

    Hi Philip this is good stuff now

  • @sanjaybhatikar
    @sanjaybhatikar 9 месяцев назад

    Thank you!

  • @ubersticks
    @ubersticks 6 месяцев назад

    I can hear Vasiliy applauding in the back of the room 😀

  • @milo4539
    @milo4539 28 дней назад

    Did you ever find a way to reset or clear the ViewModel instance without Hilt?

  • @martinseal1987
    @martinseal1987 9 месяцев назад +1

    Just as I'm porting my java app to flutter then finding flutter isn't a great fit for what I want and moving to compose instead 😂 I hated dagger hilt and am looking for a better way

  • @github.junrdev
    @github.junrdev 9 месяцев назад +1

    Just yesterday solving dagger-hilt errors,,,,,Thank you aloot

  • @vladislavmelnikov5452
    @vladislavmelnikov5452 9 месяцев назад

    Naaah, no way, I never give up on Dagger, it is been almost 3 years and I just finally understood all his power

  • @eriknyk2k
    @eriknyk2k 9 месяцев назад

    What about Koin, it would be an alternative for you or def not?

  • @MonichGPT
    @MonichGPT 5 месяцев назад

    @PhilippLackner Please tell how to create viewModel without hilt annotation but still with dependencies provided by hilt? Please please please!

  • @ChrisAthanas
    @ChrisAthanas 9 месяцев назад +1

    How about the lifetime issue, where dependencies are allowed to be released when not needed?

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад +1

      Not all singletons are used everywhere in the app, how is this handled with this technique?
      I see lazy init but what about release?

  • @nguyentu1046
    @nguyentu1046 9 месяцев назад +1

    @PhilippLackner May I know the IDE theme you are using? Thanks!

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад +3

      Android studio with new ui active

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад +2

      The default theme in the new ui in AS

    • @nguyentu1046
      @nguyentu1046 9 месяцев назад

      @@ChrisAthanas Thank a lot bro.

  • @riyupapa39
    @riyupapa39 9 месяцев назад +2

    Great video!!! But after learn manual DI, think again Hilt and Dagger is a good library.

  • @filipmanevski9872
    @filipmanevski9872 9 месяцев назад

    Does this work only on android apps or can it also work on KMM projects?

  • @bobandrews605
    @bobandrews605 9 месяцев назад +1

    nice video, but it would be also nice if you would use the latest stable android studio version with default settings, I initially always have problems to get your example projects running

    • @PhilippLackner
      @PhilippLackner  9 месяцев назад

      This is the latest stable version. You might need to select the correct jdk used in the project

    • @amarchaudhary5832
      @amarchaudhary5832 9 месяцев назад

      @@PhilippLackner and room version too, your clean architecture app works only on ver 2.4.1 for me :)

  • @MaisUmSomente
    @MaisUmSomente 7 месяцев назад

    Nice trick

  • @vibovitold
    @vibovitold 9 месяцев назад +3

    1. Dagger may be an overkill for small projects - and it's very complex (true), even intimidating.
    2. But if you find yourself creating an "AppModule" by hand... you should ask yourself: is my project really small enough not to use an industry-standard solution?
    3. It's not unlike writing your own ORM. It's easy for trivial cases, but it's dangerously close to reinventing the wheel, and the infamous NIH (Not Invented Here) syndrome.
    4. There are simpler ready-to-use alternatives if Dagger is too complex for your needs.
    Koin, for example.
    Very easy to set up, much more beginner-friendly than Dagger, and, well, battle-tested. There is a much greater chance of having a hidden bug, or an unhandled edge-case in your custom DI, than in Koin.
    5. All this being said, here is great educational value in writing a simple DI framework yourself. It really helps to understand how DI truly works, including the concepts behind Dagger. In this sense I'm fully on board.
    PS. I haven't watched the full video (yet). If some of my points are acknowledged in the video, simply treat my comment as a non-polemical summary

    • @Zhuinden
      @Zhuinden 7 месяцев назад +2

      Just because a framework is "Google-supported" doesn't mean it's technically "industry standard". Uber has Motif, Deliveryhero has Whetstone, then there's Koin, Kodein, Toothpick, Anvil. All of these predated by Guice (which "was industry-standard" and look where it is now). In the grand scheme of things, use a library because you need it, not because "it's there".

  • @trafalgarlaw3707
    @trafalgarlaw3707 8 месяцев назад

    Can you please do a video or a paid course where you use Dagger 2? It's still relevant to this day and is often asked in interviews

  • @gekylafas
    @gekylafas 9 месяцев назад

    So, providing the appContext to AppModuleImpl was not really necessary, was it? At least in those examples. Neither the -Api nor the -Repository classes need a Context.
    This is especially true for KMP projects where shared code shouldn't use Android-specific classes.

  • @nymexe
    @nymexe 9 месяцев назад +18

    KSP is coming, soon will have a faster processor 😉

  • @julesoscar8921
    @julesoscar8921 4 месяца назад

    how can i pass arguments now ?

  • @dominicblaich
    @dominicblaich 9 месяцев назад

    Hmm for me it looks like the manual DI is more work then hilt. Pure Dagger is really too much, but hilt already extracted the minimum need and you just have to add these small annotations. In this example philipp showed us you could see, that you have to write more code (at least the double), especially when you have viewModels with a lot of parameters for the constructor. Even for very small projects its still less work using hilt then doing it manually^^
    Also it is not necessary to use an interface.. for testing you can just use "mockk" for the objects.
    The only advantage for using manual DI is in my opinion the very bad compiler error messages of dagger/hilt. But when you have a bit experience, then even this errors are at some point usefull :D
    edit: As far as I know, its also not an good idea to use companion object for singletons. The Garbage Collector can garbage collect the static objects anytime. The chances are may not high, but this can happen. In Dagger/Hilt, the singletons are not static singletons, so they are also cannot randomly get garbage collected.
    Also when you really want to improve your build time, dont do manually DI but split your projects into modules. These modules can get build in parallel in really speed up you building a lot!

  • @karolkulbaka8577
    @karolkulbaka8577 9 месяцев назад

    I wasn't a big fan of koin, but koin-annotation made Hilt stop appealing to me - it's all about the configuration.

  • @olegleonov1310
    @olegleonov1310 9 месяцев назад

    Looks like service provider, but how you can create scopes for lifecycles for objects with your manual "di'?

    • @PhilippLackner
      @PhilippLackner  9 месяцев назад

      As I've mentioned in the video, you could initialize a module inside of your viewmodel for example for viewmodel scoped dependencies. For activities it's a bit trickier if the dependencies should survive config changes

    • @olegleonov1310
      @olegleonov1310 9 месяцев назад

      @@PhilippLackner I mean how we can create an object which can not be collected by GC only on two screens, for example. We have scopes in Dagger for that purpose, but how can you do it manually?

    • @PhilippLackner
      @PhilippLackner  9 месяцев назад

      If you need this, better use Dagger haha.
      You'd need to tie the creation of the module to the back stack entry (in that case of a nav sub graph) and set it to null when the back stack entry is destroyed

    • @olegleonov1310
      @olegleonov1310 9 месяцев назад

      @@PhilippLackner 🙂

  • @francoisrochefort5759
    @francoisrochefort5759 9 месяцев назад

    NICE!!!!!

  • @AlfredGuimaz
    @AlfredGuimaz 9 месяцев назад

    Don’t we need dagger for compose navigation?

  • @VishnuHaridas
    @VishnuHaridas 8 месяцев назад

    I think Kotlin should come up with a DI framework *as a part of the standard library* or a kotlinx library like Coroutines.

  • @deletedchanneI
    @deletedchanneI 9 месяцев назад

    this manual solution will work only on simple examples like in this video
    store VM-scoped modules in companion object of ViewModel? forget about simultaneous usage of VMs of this type

  • @OlegGolubev_yolo
    @OlegGolubev_yolo 7 месяцев назад

    so we reinvent the wheels? Ain't that was an ordinary stuff before dependency injection were introduced?
    I definitelly can't call this a simplier solution, unless we work on a very simple application itself

    • @PhilippLackner
      @PhilippLackner  7 месяцев назад

      Technically speaking, dagger was the reinvention of the wheel

    • @OlegGolubev_yolo
      @OlegGolubev_yolo 7 месяцев назад

      yeah, just was scarried a little bit that we going wrong way :P @@PhilippLackner

  • @Dimkar3000
    @Dimkar3000 4 месяца назад

    What this video boils down to is that DI is a pattern, not a library. Hilt is an implementation and there are other. You can also write your own. My question is: If your app is so simple that you can write your own DI solution, then maybe you don't need it at all. Just lazyinit what you need in the application class and be done with it.

  • @icodethis
    @icodethis 9 месяцев назад +1

    goat

  • @vladimirvyukov6676
    @vladimirvyukov6676 9 месяцев назад

    Thank you very much! But, how do you know, what I need right now? 😊

  • @mukulpathak9389
    @mukulpathak9389 9 месяцев назад +2

    Whole idea is to use Dagger or DI framework is to develop faster and build scalable solution also you wont know when your business gets complicated and your so called lagecy code becomes a problem to maintain. Phillip just want us to understand the DI concept but he is not discouraging you to use dagger or hilt.
    I would say if your build time is bothering you try to use service locator based DI framework (Koin) instead annotation processor based Dagger.
    Both have pros and cons but dont go with manual dependency injection for production code

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад +1

      On point

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад

      I would add this is fine for apps up until around 30,000 lines
      At that point you will likely need a solution like hilt or koin

  • @Adam0001
    @Adam0001 9 месяцев назад

    👏

  • @RishiRajxtrim
    @RishiRajxtrim 9 месяцев назад

    🎉

  • @arjun1194
    @arjun1194 6 месяцев назад +1

    This is service locator not dependency injection

  • @mikeshilovski1512
    @mikeshilovski1512 9 месяцев назад

    Koin for the win

  • @azizulhakim1380
    @azizulhakim1380 9 месяцев назад +1

    is Dagger or Hilt free?

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад +1

      Yes it’s free
      Just very steep learning curve and difficult to work with

  • @ozzy4654
    @ozzy4654 3 месяца назад

    Thats why i perfer KOIN its a great balance and simpler approach than dagger

  • @ano9161
    @ano9161 9 месяцев назад +1

    It's Wednesday again!

  • @theman3282
    @theman3282 9 месяцев назад

    mean while MAUI or xamarin is way leap ahead and this kind thing is just standard

    • @DJOrangeJoe
      @DJOrangeJoe 9 месяцев назад +1

      But MAUI xaml UI + viewmodel is a pain in the ass compared to jetpack compose :D

    • @theman3282
      @theman3282 9 месяцев назад

      @@DJOrangeJoe lol no..superb intellisense and you can code them in c# as well and biggest of all no gradle bullshit incompatible bla..bla.., plus are you not catching why DI is important and why dagger is needed back then, lol?

  • @youdube1203
    @youdube1203 9 месяцев назад

    Manual DI?

  • @Dibyendu.M
    @Dibyendu.M 9 месяцев назад

    Hey Philipp, make a project on jetpack media3. Please, consider this.

  • @aroxing
    @aroxing 6 месяцев назад

    No matter how you style it, Java is the World of Overengineering. When I started learning Kotlin I thought it was something like Python or at least Javascript but it was just a shadow of Java: patterns over patterns, libraries over libraries. Look at the DI history in Android:
    Manual Dependency Injection (pre-frameworks era)
    RoboGuice (2010)
    Dagger 1 (2012)
    Dagger 2 (2015)
    Google's Dagger Android (2017)
    Koin (2017)
    Hilt (2020)
    Koin 3 (2021)
    Want more? :)
    Here they are:
    Kodein
    ButterKnife
    DINJ
    Toothpick
    KodeGo
    Needle
    Guys, is this normal?:)

  • @John-qt6qk
    @John-qt6qk 9 месяцев назад

    😱😱

  • @josebraz5856
    @josebraz5856 8 месяцев назад

    Koin is better for small or kmp projects than manual DI

  • @BeyondOneSoul
    @BeyondOneSoul 9 месяцев назад +3

    So, you just made a service locator. Which we already have a solid solution, Koin. Even in a "small" project it's not worth to implement a manual service locator as the simplest project will scale at some point. And then you have to struggle between adapting the architecture for the new set of features or refactors and migrating your service locator to another more solid solution... Reinventing the wheel in this area is not worth it in my opinion.

    • @dreewr
      @dreewr 9 месяцев назад +1

      Koin is very error prone in large production apps...

    • @dreewr
      @dreewr 9 месяцев назад +1

      One line of code removed in a merge and your app goes to production with a crash - happened with me after QA tests, automated tests etc etc

    • @BeyondOneSoul
      @BeyondOneSoul 9 месяцев назад

      So you are telling me that a line removed in a project with QA tests, automated tests, unit tests (I'm assuming), PR reviewers and yourself testing the feature or change is going live like nothing and it's a Koin / Service locator problem? You should rethink or talk with your peeps about the current state of your project... It looks like there is space for improvement there.@@dreewr

    • @BeyondOneSoul
      @BeyondOneSoul 9 месяцев назад

      And let me tell you by my experience that you are wrong. I'm currently working in a very large bank app with multi country support and modular presentation layers (different UIs per countries) and Koin works awesome@@dreewr

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад +4

      No, these dependencies are all defined at compile time
      Service locators resolve at run time, which can easily cause problems in production

  • @louigienarvaez3019
    @louigienarvaez3019 9 месяцев назад

    I don't recommend using manual DI. It can become cumbersome and error-prone as your project grows in complexity. This is not recommended for larger projects or projects where maintainability and testability are more important than build time and gradle errors.

  • @DJOrangeJoe
    @DJOrangeJoe 9 месяцев назад

    I prefer koin over dagger. Dagger seems massively overcomplicated to me.

  • @Zhuinden
    @Zhuinden 7 месяцев назад

    You should not be passing the AppModule itself to the ViewModel, even with manual DI. Other than that, great video.

  • @mateusznepath3344
    @mateusznepath3344 9 месяцев назад

    Thank you for the video. But please... 9:56 do no leave warnings in your video code.
    People need to know that they should not leave warnings.
    I really hate it when i get into someones code and all i see i yellow color

  • @deviantstudio
    @deviantstudio 9 месяцев назад +1

    Koin ☝

  • @user-qc2yb7ki9y
    @user-qc2yb7ki9y 8 месяцев назад

    Okay, thank you, but I will still use Dagger😂😂

  • @akashsinha5148
    @akashsinha5148 9 месяцев назад +5

    Finally someone saved us from dagger's sharpness

  • @houssemzaier
    @houssemzaier 9 месяцев назад +8

    I totally disagree, I'm working on real world apps that have millions of users and more than 20 Android developers
    Using Hilt in Android development offers several advantages such as simplified configuration, reduced boilerplate code, and ease of maintenance. It automatically handles the complexities associated with component lifecycles, allowing for more streamlined and readable code. Hilt also provides compile-time validation, which makes it easier to catch errors early in the development process. By using annotations, it makes dependency injection more declarative and easier to understand, improving code readability and reducing the likelihood of mistakes. On the other hand, manual dependency injection, while offering more control, can become increasingly complex and error-prone as your project grows. Manually managing component lifecycles and dependencies can lead to a fragmented and less maintainable codebase. Additionally, the lack of compile-time validation in manual dependency injection means errors may only become apparent at runtime, making debugging more challenging.

    • @PhilippLackner
      @PhilippLackner  9 месяцев назад +3

      Then you got wrong what I wanted to show with this video, see my pinned comment :)

    • @houssemzaier
      @houssemzaier 9 месяцев назад +1

      In the video, you mentioned that you're unsure why dependency injection in Android is complicated, suggesting that perhaps Dagger Hilt solves a "mysterious problem." The complexity arises from Hilt's capability to manage dependencies using a Directed Acyclic Graph (DAG) that also takes care of the lifecycle management of the components your class relies on. This becomes increasingly challenging to handle manually in larger apps, and mistakes can lead to runtime errors. While it's true that for smaller, tutorial-level apps, you might be able to sidestep these issues, they become critical in real-world applications. These complexities not only pose a risk in terms of application stability but also contribute to productivity issues and technical debts, especially when new developers join the team. All these challenges can pose significant risks for a company.

    • @skullkrum20
      @skullkrum20 9 месяцев назад +4

      This is a lot of words to say effectively nothing..
      I’m sorry but it’s true. You’re just repeating over and over how it makes the code mor maintainable, scalable but you never mention why you think that?
      Also I am not sure what compile time safety you think you get with dagger hilt that you don’t get with manual DI?
      You have all the safety with manual DI. Your app will not compile if you don’t provide all dependencies since you’re the one calling the constructors.
      Dagger / hilt is easier to understand and maintain then plain Kotlin code? I’m sorry but if you don’t understand Kotlin code then how will you understand any other part of your code base?

    • @houssemzaier
      @houssemzaier 9 месяцев назад

      @@skullkrum20 I'm so sorry for you if you didn't understand the meaning, and sorry it's really obvious what does it mean scalability and maintanabilty when you have experience.
      When you write less code you get less errors so better maintenance.

    • @houssemzaier
      @houssemzaier 9 месяцев назад

      @@skullkrum20 with manual DI you are never safe. And especially when you have a lot of contains in the app, while you are trying to resolve memory problems related to the lifecycle of your app

  • @marta_na_moto
    @marta_na_moto 9 месяцев назад

    I hate dagger with a passion but reinventing the wheel is not the way.. however k..k..koin ? ;))

    • @dreewr
      @dreewr 9 месяцев назад +1

      It's not reinventing the wheel, it's the wheel itself. The pattern is agnostic of the tools that implement it.

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад +1

      @@dreewragree
      This is what the DI is doing under the hood anyway
      Dagger/Hilt is an overcomplicated mess and often causes more problems than it solves and the documentation is TERRIBLE
      Thermosiphon this! Lol

  • @mackomako
    @mackomako 9 месяцев назад

    Thanks for showing us how DI works. But why bother to write all this boiler plate code? Hilt is stupidly easy to set up and use. Build time is not an issue for small projects. For bigger projects, you can go multimodule to slash down build times to almost nothing. I would not go with manual DI setup for any production app.
    And small comparison between Koin vs Dagger2/Hilt: during runtime Dagger2/Hilt has only ~third of memory footprint of Koin.
    Everything has pros and cons. Choose wisely :)

  • @GTechYoutube
    @GTechYoutube 8 месяцев назад

    I don't understand why this much work for simple work, just use objects that will solve most of your singleton problems

  • @Dibyendu.M
    @Dibyendu.M 9 месяцев назад

    I feel like Hilt is easier than this. 😅

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад +1

      Only because you have trudged up the mountain and are confiable with its methodology
      Can you remember your first encounter with hilt/dagger and how it felt
      This approach is a better step before full blown hilt implementation

    • @Dibyendu.M
      @Dibyendu.M 9 месяцев назад +1

      @@ChrisAthanas Indeed, it was not easy for me until I implemented this in my projects.

    • @ChrisAthanas
      @ChrisAthanas 9 месяцев назад +1

      @@Dibyendu.M exactly
      The technique given here is a very useful in-between step
      Shows the reason why a DI library is necessary but only after you fully understand it
      Deploying the solution with Kotlin is a great way to introduce the DI concept, because it's very clear what's going on, so adding a DI library will be much less confusing

  • @argahutama
    @argahutama 9 месяцев назад +2

    I disagree with this, especially when you're working with big Android team.

  • @pyaesonehan19
    @pyaesonehan19 Месяц назад

  • @omaryousifkamal4290
    @omaryousifkamal4290 9 месяцев назад +1

    goat