The Ultimate Guide to Koin (Dependency Injection with Kotlin) - Android Studio Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ก.พ. 2025
  • Dependency injection is a crucial concept for every software developer. This video will show you how you can use the Koin library to do that in Kotlin.
    ⭐ Get certificates for your future job
    ⭐ Save countless hours of time
    ⭐ 100% money back guarantee for 30 days
    ⭐ Become a professional Android developer now:
    pl-coding.com/...
    💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:
    elopage.com/s/...
    🎓 Become an industry-ready developer in the Mobile Dev Campus:
    pl-coding.com/...
    🎁 Get my FREE 4.5h course "The Best Practice Guide to Android Architecture":
    pl-coding.com/...
    Read our weekly Android blog:
    pl-coding.com/...
    Join this channel to get access to perks:
    / @philipplackner
    Get the source code for this video here:
    github.com/phi...
    Join my Discord server:
    / discord
    Regular programming advice on my Instagram page: / _philipplackner_
    Checkout my GitHub: github.com/phi...
    You like my free content? Here you can buy me a coffee:
    www.buymeacoff...

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

  • @VanWyn7
    @VanWyn7 9 หลายเดือนก่อน +11

    Most Koin videos I've seen were like "here I show you a project with Dagger and migrate to Koin" or "You add this, this and this and voila, it works". But your video was exactly what a tutorial must be: explaining things step by step and made me understand it. Thank you!

  • @anshumandhal
    @anshumandhal 2 ปีที่แล้ว +13

    A couple of weeks ago I was hoping that you would make a tutorial on Koin and you did. Thank you 😁

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

    When you say, "most people overcomplicated", it reminded me of the old dagger documentation which gives the thermosiphon example 😃
    Nice video btw, thanks!

  • @unaisulhadi9102
    @unaisulhadi9102 2 ปีที่แล้ว +4

    Really helpful, I was unaware of how to handle named injection like Hilt. Thanks

  • @snehilsinha4689
    @snehilsinha4689 2 ปีที่แล้ว +33

    my takeaway from the video 12:24 - single{
    } // is life of a programmer XD

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

    I'm looking into Koin after just getting really frustrated with Dagger Hilt and wow this is much easier and more flexible than hilt is. Time to migrate to Koin!

  • @akashkumardas6521
    @akashkumardas6521 2 ปีที่แล้ว +6

    I worry about you, how you provide such great contents for free? Thank you so much sir.

    • @clamum9648
      @clamum9648 2 ปีที่แล้ว +4

      Do not worry about Philipp he is a gigachad

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

    Clear explanation. Thanks philipp

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

    Just the video I was needing. Thank you!

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

    It's really helpful. Thanks Lackner

  • @ThanhNguyen-sl2kd
    @ThanhNguyen-sl2kd 2 ปีที่แล้ว +8

    I only used Hilt before but definitely gonna try this. The idea of inject at runtime is very interesting!
    However Hilt is backed by Google though, this is not a fair fight 🙂

    • @PhilippLackner
      @PhilippLackner  2 ปีที่แล้ว +14

      Just because it has the Google badge, doesn't mean it's good😅

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

      For hilt though, I agree 😁

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

      Simplicity vs Complexity. Single platform vs Multi platform. Koin is both simple to use and work with Kotlin Multiplatform Mobile.

    • @Joey-ni8kh
      @Joey-ni8kh 2 ปีที่แล้ว +3

      Don’t worry give it time. It will be retired like everything else

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

      @@Joey-ni8kh ^^ this ^^

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

    this is such a nice video. Thanks Philipp.

  • @original_anu
    @original_anu 2 ปีที่แล้ว +9

    Koin being an easy to use service locater without any proxies, code generation or reflection can attract many people.

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

      It uses reflection

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

    Great video as always keep it up!!!! Love you!

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

    Thanks a lot Philipp for your guide, really great work 🙏

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

    Very cool video
    thank you bro wish you all the best 👍👍👍🔥🔥🔥🔥

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

    Thanks for making this video.

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

    With you i learn Android and english :D

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

    Nice explanation! THX

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

    Wow you make it very understandable. Thank you

  • @codinginflow
    @codinginflow 2 ปีที่แล้ว +4

    Ko-een 😂

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

    Excellent tutorial bro - very relevant..

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

    Interesting. it looks so simple.

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

    Philipp can you make a tutorial about savedStateHandle? How and when to save data and how to retrieve? Thank you.

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

    Thank you for the video , very helpful

  • @eluroalex5920
    @eluroalex5920 11 หลายเดือนก่อน

    Philipp actually dropped a joke on 12:23 🤣

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

    Wow man. Respect.

  • @janssenbatista
    @janssenbatista 11 หลายเดือนก่อน

    Thanks a lot. 😊

  • @jaya-surya-t
    @jaya-surya-t 2 ปีที่แล้ว

    Hey, Phillip. Chapters would be clutch for this video.

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

    U r gr8 like always keep going up thank you. Single joke was good😅. Can you tell savedstatehandle with koin pls

  • @517Amit
    @517Amit 2 ปีที่แล้ว

    I love to watch your videos 😍

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

    Thank you so much!

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

    12:25 EMOTIONAL DAMAGE !

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

    Ty for this video!

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

    Thank you for your awesome contents.

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

    Soo easy to use koin, hello from russia)

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

    Could you do a video on baseline profiles, looks like a great way to increase app start performance

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

    Could you pls upload a video with paging and how we can implement it with Resource class

  • @mo_2212
    @mo_2212 17 วันที่ผ่านมา

    Something hilarius happened before he makes the video, bc he spent all the video trying to avoid laugh out loud xDDD

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

    single : when i write that i don't want to talk about the life of the programmer, that actually means singleton 😂

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

    Hey! Great video :D Can you do any tutorials on Anvil? It seems the community is really lacking some solid examples of its usage.

  • @matt-g-recovers
    @matt-g-recovers 2 ปีที่แล้ว

    Nice...reminds me.
    .have you done KTOR?
    I need to review your library again

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

      He's got a bunch of KTOR videos

  • @gabrielpetrutbadicioiu
    @gabrielpetrutbadicioiu 11 หลายเดือนก่อน

    Where did you get all these dependencies from? I didn't see them in the documentation I found online.

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

    which one that you most recommend Koin or Hilt?

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

      @Houssem Zaier nice simple answer bro

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

    this is awesome! QQ: what if in the viewmodel constructor we need 2 or more dependency? how we inject that dependency? thanks

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

    Before Dagger Hilt I used to work with koin. It was my first DI library. Then I tried Dagger Hilt and I liked it more))) Hilt was more easier for me to get used to it. Maybe I prefer annotation processing over DSL))

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

    But viewmodel keyword in Koin acts as a factory? And if we want to share the VM in two fragments por example, can we use viewmodel injection like a singleton?

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

    Can you make a video about the mavericks framework?

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

    Hello sir can you make a tutorial about mobile banking apps. like Bkash is very advance apps in Bangladesh.

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

    I always find DI at runtime kinda dangerous. When you have multiple flow, it is easy to miss one and you will only notice when running it.

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

      Koin for small apps.
      Hilt/Dagger for big apps.

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

      ​@@D3vCansado You will be surprised how many times I saw these "very simple test cases" not implemented and caused prod bugs. Especially after 2 years and 4 dev changes. This is why I prefer compile time over run time.
      I also need to say that Dagger series was kinda hard to use compared to Koin but I feel using Hilt almost easy as Koin.

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

      ​@@D3vCansado There are always issues. This is why I don't want to introduce another possible problem. Pipelines, health checks, security checks fails time to time and they might be ignored to deliver prod on time. (They always say they will see at regression/sanity checks if there is a problem)
      On the one hand, there are tests that I need to trust, and on the other hand, the direct error I will get while doing development. For me it is a clear choice.
      Anyway, I'm happy that there is more than one DI library. So we can use the library that suits us best.

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

    When you are creating a Library, we can't use HILT for dependency injection as we can't force the consumer to integrate HILT in their project. I believe then KOIN is life saviour.

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

    What about preview? How to organise preview with viewModel and Koin? ay be a good them for video)

  • @FarhazulMullick-rh6be
    @FarhazulMullick-rh6be ปีที่แล้ว

    Cannot use koinComponents with KoinApplication composable fn any help?
    .

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

    12:24 single 🤣

  • @ralphmaron
    @ralphmaron 11 วันที่ผ่านมา

    when you talk about the creation of module, on the `single` part, not talking about the life of a programmer😂😂😂😂😂😂

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

    so which one is good hit or koin?

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

    The main difference is that Koin is a PURE Kotlin library and Hilt NOT, therefore Koin can be used in KMM/D-KMP projects where Hilt cannot!

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

    perfecto

  • @er.harsh_rathore
    @er.harsh_rathore 2 ปีที่แล้ว

    Is koin module completely Kotlin based, can we use it with KMM? As we know we can not use dagger-hilt there 🙅‍♂️

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

    Hello sir, I am confuse right now my plan is to learn Android development but when I see there are too many videos on the youtube and Fb groups peopls are doing with Flutter right now , ma aim is to get a job in android development can you please guid me what i do , should I need to start with the Kotlin programming or start as a Flutter , I want to do a Job in Android Development. plz answer my question.

    • @Momo-zi2hi
      @Momo-zi2hi 2 ปีที่แล้ว +1

      Both are great ways to develop apps, but if you want to become an android developer, you should learn the android sdk

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

      Start as a Fluffer

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

    You still use koin on your project?

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

    Btw big 🐕 isn't it pronounced the same as "coin" is, like the little metal pieces of currency?

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

    '....don't wanna talk about the life of a programmer' 😂😂😂

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

    Koin isn't dependency injection actually. It's a service locator. The end result is pretty much the same, both provide dependency, however they do it differently and hilt does it much faster, because it's done at compile time. In other words Koin has no build time impact, but has a runtime one. The opposite is true for hilt.

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

      And that's what I said in the video :)

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

      @@PhilippLackner yeah, I kinda commented before watching the whole thing.

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

    what color theme is that?

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

    how to inject constructor?

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

    What if my adapter looks like this RouteAdapter(val clickCallback: (Route) -> Unit
    Then we are creating what inside module? :D
    and what if my repository looks like this
    class Repository(
    private val routeApi: RouteApi,
    private val RouteCacheDataSource: RouteCacheDataSource
    ) and my koin need this 2 dependency? ^^ just we have to use Repository(get(), get()) ?: P

  • @DEVENDRA-r3p
    @DEVENDRA-r3p 5 หลายเดือนก่อน

    single not about life of programmer😂

  • @Mohit-il9gx
    @Mohit-il9gx 2 ปีที่แล้ว

    Can you teach how to make website using kotlin or please link any tutorial below

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

    The domain name is literally "insert-koin". It's obviously intended to be pronounced "coin"!

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

    Wait, you're telling me it isn't said "Coin"?!?

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

      I'm pretty sure it is, it wouldn't make a heck of a lotta sense if that wasn't the case.

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

    "Single, but I'm not talking about the life of a programmer"
    🤭
    ...
    🤔
    🥺🔫
    Looks like KOIN might be a little easier to setup than Dagger/Hilt. Not that that's difficult but there is a series of things you need to setup to use it. May check out KOIN for my next project thanks for showing it big 🐕

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

    Single = The life of a programmer😂

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

    I like koin more

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

    12:23 Come on man... :(

  •  2 ปีที่แล้ว

    Brorher

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

    Wrong title

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

    Philipp - I am trying to use mockito to mock an object that is passed as an argument to the constructor of myViewModel(val dice:Dice).
    within the Dice class I just have a single method called roll() that just returns a random number between 1..6. It is not
    It is not returning 3?
    This is how my instrumentation setup:
    @Before
    fun init(){
    stopKoin()
    diceMock = mock(Dice::class.java)
    `when`(diceMock.roll()).thenReturn(3)
    val testModule = module {
    single { diceMock }
    viewModel{
    DiceViewModel(diceMock)
    }
    }
    startKoin{
    // loadKoinModules(testModule)
    modules(testModule)
    }
    }
    @Test
    fun roll_displaysNumber() {
    `when`(diceMock.roll()).thenReturn(3)
    onView(withId(R.id.button)).perform(click())
    onView(withId(R.id.textView)).check(matches(isDisplayed()))
    }

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