Full Guide to Manual Dependency Injection + Removing Dagger

แชร์
ฝัง
  • เผยแพร่เมื่อ 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...

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

  • @PhilippLackner
    @PhilippLackner  10 หลายเดือนก่อน +82

    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 10 หลายเดือนก่อน +4

      Now I agree 👍 good clarification

    • @ChrisAthanas
      @ChrisAthanas 10 หลายเดือนก่อน

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

    • @paulsoja2732
      @paulsoja2732 10 หลายเดือนก่อน

      And what about scopes?

    • @houssemzaier
      @houssemzaier 10 หลายเดือนก่อน

      @@paulsoja2732 this when manual DI fails

    • @houssemzaier
      @houssemzaier 10 หลายเดือนก่อน

      @@ChrisAthanas a jvm singleton is never released

  • @ErdemKalyoncu
    @ErdemKalyoncu 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน

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

  • @mark-147
    @mark-147 10 หลายเดือนก่อน +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.

  • @vitalijuskolinko9011
    @vitalijuskolinko9011 10 หลายเดือนก่อน +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 ;)
    🇱🇹

  • @mohamedalaa6yahoo
    @mohamedalaa6yahoo 6 หลายเดือนก่อน

    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 😄

  • @FabioSangregorio-od4qv
    @FabioSangregorio-od4qv 10 หลายเดือนก่อน

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

  • @jenovas00
    @jenovas00 10 หลายเดือนก่อน +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  10 หลายเดือนก่อน +24

      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 10 หลายเดือนก่อน +8

      Koin

    • @ShaqarudenGames
      @ShaqarudenGames 10 หลายเดือนก่อน +1

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

    • @marekgajda838
      @marekgajda838 10 หลายเดือนก่อน +5

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

    • @leslied7456
      @leslied7456 10 หลายเดือนก่อน +2

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

  • @MMateos97
    @MMateos97 10 หลายเดือนก่อน +1

    The best Android related videos on TH-cam 👌

    • @ChrisAthanas
      @ChrisAthanas 10 หลายเดือนก่อน +1

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

  • @tch.777
    @tch.777 10 หลายเดือนก่อน

    Thank you Philipp you are the best 🙏🔥

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

    i really enjoy your videos. thanks!

  • @JazzyJesterTechPing
    @JazzyJesterTechPing 10 หลายเดือนก่อน

    Thanks, nice approach !

  • @yosipipi
    @yosipipi 10 หลายเดือนก่อน +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 ;)

  • @senk0n
    @senk0n 10 หลายเดือนก่อน +1

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

    • @ChrisAthanas
      @ChrisAthanas 10 หลายเดือนก่อน

      Annotations are so confusing and messy

  • @karolkulbaka8577
    @karolkulbaka8577 10 หลายเดือนก่อน +1

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

  • @ibrahimanimasahun9431
    @ibrahimanimasahun9431 10 หลายเดือนก่อน +4

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

    • @PhilippLackner
      @PhilippLackner  10 หลายเดือนก่อน

      😂

    • @vibovitold
      @vibovitold 10 หลายเดือนก่อน

      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.

  • @ojo_lali_ngaji
    @ojo_lali_ngaji 10 หลายเดือนก่อน

    always make usefull content 🤝

  • @alexteodorovici_yt
    @alexteodorovici_yt 10 หลายเดือนก่อน

    Awesome, thank you 😀

  • @MegaAntarioGames
    @MegaAntarioGames 10 หลายเดือนก่อน +1

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

  • @serlok4688
    @serlok4688 10 หลายเดือนก่อน +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.

  • @riyupapa39
    @riyupapa39 10 หลายเดือนก่อน +2

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

  • @denisgithuku8563
    @denisgithuku8563 10 หลายเดือนก่อน

    Hi Philip this is good stuff now

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

    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?

  • @sanjaybhatikar
    @sanjaybhatikar 10 หลายเดือนก่อน

    Thank you!

  • @martinseal1987
    @martinseal1987 10 หลายเดือนก่อน +1

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

  • @ubersticks
    @ubersticks 7 หลายเดือนก่อน

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

  • @ahmadrezasariaslani4650
    @ahmadrezasariaslani4650 10 หลายเดือนก่อน

    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  10 หลายเดือนก่อน

      The type is specified by the function return type

  • @aroxing
    @aroxing 7 หลายเดือนก่อน +1

    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?:)

  • @kdbrian.d3v
    @kdbrian.d3v 10 หลายเดือนก่อน +1

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

  • @wigs_n_roses
    @wigs_n_roses 10 หลายเดือนก่อน

    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  10 หลายเดือนก่อน +1

      It's all focused on compose 💪🏻

    • @wigs_n_roses
      @wigs_n_roses 10 หลายเดือนก่อน

      @@PhilippLackner great, than I will buy!

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

    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.

  • @nguyentu1046
    @nguyentu1046 10 หลายเดือนก่อน +1

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

    • @ChrisAthanas
      @ChrisAthanas 10 หลายเดือนก่อน +3

      Android studio with new ui active

    • @ChrisAthanas
      @ChrisAthanas 10 หลายเดือนก่อน +2

      The default theme in the new ui in AS

    • @nguyentu1046
      @nguyentu1046 10 หลายเดือนก่อน

      @@ChrisAthanas Thank a lot bro.

  • @bungholici-gg5vt
    @bungholici-gg5vt 10 หลายเดือนก่อน

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

  • @mohamadrezamehrjou9553
    @mohamadrezamehrjou9553 10 หลายเดือนก่อน

    Great video thank you Philipp

  • @vladislavmelnikov5452
    @vladislavmelnikov5452 10 หลายเดือนก่อน

    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 10 หลายเดือนก่อน

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

  • @nymexe
    @nymexe 10 หลายเดือนก่อน +19

    KSP is coming, soon will have a faster processor 😉

    • @PhilippLackner
      @PhilippLackner  10 หลายเดือนก่อน +19

      Video is already planned :D

    • @RishiRajxtrim
      @RishiRajxtrim 10 หลายเดือนก่อน

      Great

  • @milo4539
    @milo4539 2 หลายเดือนก่อน

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

  • @MonichGPT
    @MonichGPT 6 หลายเดือนก่อน

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

  • @filipmanevski9872
    @filipmanevski9872 10 หลายเดือนก่อน

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

  • @ChrisAthanas
    @ChrisAthanas 10 หลายเดือนก่อน +1

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

    • @ChrisAthanas
      @ChrisAthanas 10 หลายเดือนก่อน +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?

  • @martinseal1987
    @martinseal1987 10 หลายเดือนก่อน +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

  • @bobandrews605
    @bobandrews605 10 หลายเดือนก่อน +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  10 หลายเดือนก่อน

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

    • @amarchaudhary5832
      @amarchaudhary5832 10 หลายเดือนก่อน

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

  • @dominicblaich
    @dominicblaich 10 หลายเดือนก่อน

    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!

  • @trafalgarlaw3707
    @trafalgarlaw3707 9 หลายเดือนก่อน

    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

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

    Nice trick

  • @mukulpathak9389
    @mukulpathak9389 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน +1

      On point

    • @ChrisAthanas
      @ChrisAthanas 10 หลายเดือนก่อน

      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

  • @francoisrochefort5759
    @francoisrochefort5759 10 หลายเดือนก่อน

    NICE!!!!!

  • @vibovitold
    @vibovitold 10 หลายเดือนก่อน +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 8 หลายเดือนก่อน +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".

  • @icodethis
    @icodethis 10 หลายเดือนก่อน +1

    goat

  • @VishnuHaridas
    @VishnuHaridas 9 หลายเดือนก่อน

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

  • @olegleonov1310
    @olegleonov1310 10 หลายเดือนก่อน

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

    • @PhilippLackner
      @PhilippLackner  10 หลายเดือนก่อน

      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 10 หลายเดือนก่อน

      @@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  10 หลายเดือนก่อน

      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 10 หลายเดือนก่อน

      @@PhilippLackner 🙂

  • @Dimkar3000
    @Dimkar3000 6 หลายเดือนก่อน

    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.

  • @AlfredGuimaz
    @AlfredGuimaz 10 หลายเดือนก่อน

    Don’t we need dagger for compose navigation?

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

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

  • @Scotthutchinsonking
    @Scotthutchinsonking 18 วันที่ผ่านมา

    I thought the whole time I was crazy for thinking dagger was overcomplicated coming from a .NET where injection is baked in

  • @julesoscar8921
    @julesoscar8921 6 หลายเดือนก่อน

    how can i pass arguments now ?

  • @deletedchanneI
    @deletedchanneI 10 หลายเดือนก่อน

    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

  • @Adam0001
    @Adam0001 10 หลายเดือนก่อน

    👏

  • @mikeshilovski1512
    @mikeshilovski1512 10 หลายเดือนก่อน

    Koin for the win

  • @azizulhakim1380
    @azizulhakim1380 10 หลายเดือนก่อน +1

    is Dagger or Hilt free?

    • @ChrisAthanas
      @ChrisAthanas 10 หลายเดือนก่อน +1

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

  • @ano9161
    @ano9161 10 หลายเดือนก่อน +1

    It's Wednesday again!

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

    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  8 หลายเดือนก่อน

      Technically speaking, dagger was the reinvention of the wheel

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

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

  • @Dibyendu.M
    @Dibyendu.M 10 หลายเดือนก่อน

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

  • @RishiRajxtrim
    @RishiRajxtrim 10 หลายเดือนก่อน

    🎉

  • @arjun1194
    @arjun1194 8 หลายเดือนก่อน +1

    This is service locator not dependency injection

  • @youdube1203
    @youdube1203 10 หลายเดือนก่อน

    Manual DI?

  • @theman3282
    @theman3282 10 หลายเดือนก่อน

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

    • @DJOrangeJoe
      @DJOrangeJoe 10 หลายเดือนก่อน +1

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

    • @theman3282
      @theman3282 10 หลายเดือนก่อน

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

  • @vladimirvyukov6676
    @vladimirvyukov6676 10 หลายเดือนก่อน

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

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

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

  • @josebraz5856
    @josebraz5856 9 หลายเดือนก่อน

    Koin is better for small or kmp projects than manual DI

  • @louigienarvaez3019
    @louigienarvaez3019 10 หลายเดือนก่อน

    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.

  • @John-qt6qk
    @John-qt6qk 10 หลายเดือนก่อน

    😱😱

  • @BeyondOneSoul
    @BeyondOneSoul 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน +1

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

    • @dreewr
      @dreewr 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน

      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 10 หลายเดือนก่อน

      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 10 หลายเดือนก่อน +4

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

  • @gekylafas
    @gekylafas 10 หลายเดือนก่อน

    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.

  • @user-qc2yb7ki9y
    @user-qc2yb7ki9y 9 หลายเดือนก่อน

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

  • @mateusznepath3344
    @mateusznepath3344 10 หลายเดือนก่อน

    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

  • @DJOrangeJoe
    @DJOrangeJoe 10 หลายเดือนก่อน

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

  • @akashsinha5148
    @akashsinha5148 10 หลายเดือนก่อน +5

    Finally someone saved us from dagger's sharpness

  • @deviantstudio
    @deviantstudio 10 หลายเดือนก่อน +1

    Koin ☝

  • @houssemzaier
    @houssemzaier 10 หลายเดือนก่อน +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  10 หลายเดือนก่อน +3

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

    • @houssemzaier
      @houssemzaier 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน

      @@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 10 หลายเดือนก่อน

      @@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 10 หลายเดือนก่อน

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

    • @dreewr
      @dreewr 10 หลายเดือนก่อน +1

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

    • @ChrisAthanas
      @ChrisAthanas 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน

    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 9 หลายเดือนก่อน

    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 10 หลายเดือนก่อน

    I feel like Hilt is easier than this. 😅

    • @ChrisAthanas
      @ChrisAthanas 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน +1

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

    • @ChrisAthanas
      @ChrisAthanas 10 หลายเดือนก่อน +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 10 หลายเดือนก่อน +2

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

  • @pyaesonehan19
    @pyaesonehan19 2 หลายเดือนก่อน

  • @omaryousifkamal4290
    @omaryousifkamal4290 10 หลายเดือนก่อน +1

    goat