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

  Рет қаралды 47,599

Philipp Lackner

Philipp Lackner

2 жыл бұрын

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/premium-courses...
💻 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/philipplackner/...
Subscribe to my FREE newsletter for regular Android, Kotlin & Architecture advice!
pl-coding.com/newsletter
Join this channel to get access to perks:
/ @philipplackner
Get the source code for this video here:
github.com/philipplackner/Koi...
Join my Discord server:
/ discord
Regular programming advice on my Instagram page: / _philipplackner_
Checkout my GitHub: github.com/philipplackner
You like my free content? Here you can buy me a coffee:
www.buymeacoffee.com/philippl...

Пікірлер: 105
@VanWyn7
@VanWyn7 3 ай бұрын
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 жыл бұрын
A couple of weeks ago I was hoping that you would make a tutorial on Koin and you did. Thank you 😁
@snehilsinha4689
@snehilsinha4689 2 жыл бұрын
my takeaway from the video 12:24 - single{ } // is life of a programmer XD
@romanhruska7402
@romanhruska7402 Жыл бұрын
I almost fell of my chair :D
@KunalGoyal
@KunalGoyal 3 ай бұрын
Lmao 😂😂
@christiancamilootero8944
@christiancamilootero8944 2 жыл бұрын
Just the video I was needing. Thank you!
@original_anu
@original_anu 2 жыл бұрын
Koin being an easy to use service locater without any proxies, code generation or reflection can attract many people.
@unaisulhadi9102
@unaisulhadi9102 2 жыл бұрын
Really helpful, I was unaware of how to handle named injection like Hilt. Thanks
@0xTyfn
@0xTyfn Жыл бұрын
When you say, "most people overcomplicated", it reminded me of the old dagger documentation which gives the thermosiphon example 😃 Nice video btw, thanks!
@kotzilla1983
@kotzilla1983 Жыл бұрын
Thanks a lot Philipp for your guide, really great work 🙏
@rijalmyd
@rijalmyd 2 жыл бұрын
Clear explanation. Thanks philipp
@Ameya890
@Ameya890 2 жыл бұрын
Great video as always keep it up!!!! Love you!
@ren7907
@ren7907 Жыл бұрын
this is such a nice video. Thanks Philipp.
@GanjaBro99
@GanjaBro99 2 жыл бұрын
Wow you make it very understandable. Thank you
@ShaqarudenGames
@ShaqarudenGames 2 жыл бұрын
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!
@awaqar2
@awaqar2 Жыл бұрын
Excellent tutorial bro - very relevant..
@luisenriquemendezcantero9508
@luisenriquemendezcantero9508 Жыл бұрын
Nice explanation! THX
@nilaytagove7497
@nilaytagove7497 2 жыл бұрын
Interesting. it looks so simple.
@muneerhasan
@muneerhasan 2 жыл бұрын
Thanks for making this video.
@mustafaammar551
@mustafaammar551 2 жыл бұрын
Very cool video thank you bro wish you all the best 👍👍👍🔥🔥🔥🔥
@AlgeriaHere
@AlgeriaHere 2 жыл бұрын
Thank you for the video , very helpful
@RahmatKhanZai89
@RahmatKhanZai89 2 жыл бұрын
Thank you for your awesome contents.
@datel666
@datel666 2 жыл бұрын
Ty for this video!
@jeffGordon852
@jeffGordon852 Жыл бұрын
Thank you so much!
@akashkumardas6521
@akashkumardas6521 2 жыл бұрын
I worry about you, how you provide such great contents for free? Thank you so much sir.
@clamum9648
@clamum9648 2 жыл бұрын
Do not worry about Philipp he is a gigachad
@youmeandeveryone5893
@youmeandeveryone5893 2 жыл бұрын
Wow man. Respect.
@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.
@517Amit
@517Amit 2 жыл бұрын
I love to watch your videos 😍
@janssenbatista
@janssenbatista 5 ай бұрын
Thanks a lot. 😊
@anudeepananth
@anudeepananth 2 жыл бұрын
Could you do a video on baseline profiles, looks like a great way to increase app start performance
@eluroalex5920
@eluroalex5920 5 ай бұрын
Philipp actually dropped a joke on 12:23 🤣
@sodiqjonrasulov4231
@sodiqjonrasulov4231 Жыл бұрын
It's really helpful. Thanks Lackner
@codinginflow
@codinginflow 2 жыл бұрын
Ko-een 😂
@miladhashemzadeh5626
@miladhashemzadeh5626 2 жыл бұрын
U r gr8 like always keep going up thank you. Single joke was good😅. Can you tell savedstatehandle with koin pls
@valish_
@valish_ 2 жыл бұрын
With you i learn Android and english :D
@jaya-surya-t
@jaya-surya-t 2 жыл бұрын
Hey, Phillip. Chapters would be clutch for this video.
@haykmkrtchyan7093
@haykmkrtchyan7093 2 жыл бұрын
Philipp can you make a tutorial about savedStateHandle? How and when to save data and how to retrieve? Thank you.
@EmanNollase
@EmanNollase Жыл бұрын
this is awesome! QQ: what if in the viewmodel constructor we need 2 or more dependency? how we inject that dependency? thanks
@ThanhNguyen-sl2kd
@ThanhNguyen-sl2kd 2 жыл бұрын
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 жыл бұрын
Just because it has the Google badge, doesn't mean it's good😅
@PhilippLackner
@PhilippLackner 2 жыл бұрын
For hilt though, I agree 😁
@MrParadoxia1
@MrParadoxia1 2 жыл бұрын
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 жыл бұрын
Don’t worry give it time. It will be retired like everything else
@jayshartzer844
@jayshartzer844 2 жыл бұрын
@@Joey-ni8kh ^^ this ^^
@rajithprasathbalasundaram254
@rajithprasathbalasundaram254 2 жыл бұрын
Could you pls upload a video with paging and how we can implement it with Resource class
@GulshanTaksande
@GulshanTaksande Ай бұрын
single : when i write that i don't want to talk about the life of the programmer, that actually means singleton 😂
@gabrielpetrutbadicioiu787
@gabrielpetrutbadicioiu787 5 ай бұрын
Where did you get all these dependencies from? I didn't see them in the documentation I found online.
@ankitverma3932
@ankitverma3932 2 жыл бұрын
12:25 EMOTIONAL DAMAGE !
@albertbo2178
@albertbo2178 6 ай бұрын
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?
@FarhazulMullick-rh6be
@FarhazulMullick-rh6be 8 ай бұрын
Cannot use koinComponents with KoinApplication composable fn any help? .
@ThePratik822
@ThePratik822 Жыл бұрын
so which one is good hit or koin?
@josua_htp
@josua_htp 2 жыл бұрын
what color theme is that?
@dragonz9977
@dragonz9977 2 жыл бұрын
Can you make a video about the mavericks framework?
@mohamadrezazandieh3003
@mohamadrezazandieh3003 7 ай бұрын
perfecto
@tikhon2185
@tikhon2185 11 ай бұрын
Soo easy to use koin, hello from russia)
@whoknows3606
@whoknows3606 2 жыл бұрын
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 жыл бұрын
​@@_th3j4ck4l 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 жыл бұрын
​@@_th3j4ck4l 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.
@FreedivingTrainer
@FreedivingTrainer 2 жыл бұрын
What about preview? How to organise preview with viewModel and Koin? ay be a good them for video)
@tarannumkhan5943
@tarannumkhan5943 6 ай бұрын
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.
@clamum9648
@clamum9648 2 жыл бұрын
Btw big 🐕 isn't it pronounced the same as "coin" is, like the little metal pieces of currency?
@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 🙅‍♂️
@tiltedbybox6118
@tiltedbybox6118 2 жыл бұрын
Koin is available for KMM.
@mattgraves3709
@mattgraves3709 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
@uziroid
@uziroid 2 жыл бұрын
which one that you most recommend Koin or Hilt?
@houssemzaier
@houssemzaier 2 жыл бұрын
Koin is not recommended for any kind of serious programming, it is a service locator so you can say it's based on an anti pattern solution.
@uziroid
@uziroid 2 жыл бұрын
@@houssemzaier nice simple answer bro
@kigaming1813
@kigaming1813 Жыл бұрын
how to inject constructor?
@mytubekt
@mytubekt Жыл бұрын
12:24 single 🤣
@CryptoCodeZone
@CryptoCodeZone Жыл бұрын
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!
@shariarhossain1582
@shariarhossain1582 2 жыл бұрын
Hello sir can you make a tutorial about mobile banking apps. like Bkash is very advance apps in Bangladesh.
@arfinhosain
@arfinhosain 2 жыл бұрын
You still use koin on your project?
@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 жыл бұрын
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
@haykmkrtchyan7093
@haykmkrtchyan7093 2 жыл бұрын
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))
@helderfsv
@helderfsv Жыл бұрын
'....don't wanna talk about the life of a programmer' 😂😂😂
@shivamkadam9347
@shivamkadam9347 Жыл бұрын
I like koin more
@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
@Mohit-il9gx
@Mohit-il9gx 2 жыл бұрын
Can you teach how to make website using kotlin or please link any tutorial below
@wasabinator
@wasabinator Ай бұрын
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.
@ammarseud5461
@ammarseud5461 2 жыл бұрын
12:23 Come on man... :(
@azamat0180
@azamat0180 2 жыл бұрын
Single = The life of a programmer😂
@tiltedbybox6118
@tiltedbybox6118 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 жыл бұрын
And that's what I said in the video :)
@tiltedbybox6118
@tiltedbybox6118 2 жыл бұрын
@@PhilippLackner yeah, I kinda commented before watching the whole thing.
2 жыл бұрын
Brorher
@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 🐕
@kamleshpandey1650
@kamleshpandey1650 2 жыл бұрын
Wrong title
@PhilippLackner
@PhilippLackner 2 жыл бұрын
?
@kamleshpandey1650
@kamleshpandey1650 2 жыл бұрын
My bad
@houssemzaier
@houssemzaier 2 жыл бұрын
Developers that prefer to use Koin for DI in place of Dagger Hilt are just stupid. Sorry 😐
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Developers who generalize the right way to code without arguments are just stupid. Sorry 😐
@anshumandhal
@anshumandhal 2 жыл бұрын
Developers who use KMM cannot use Dagger hilt since it's a Java based library. Koin on the other hand is written entirely in Kotlin. Like other libraries it's just a tool. Not every job requires the same tools to get the work done.
@houssemzaier
@houssemzaier 2 жыл бұрын
Koin is not recommended for any kind of serious programming, it is a service locator so you can say it's based on an anti pattern solution. Just use Hilt or manual DI for KMM. Remember that you will have a very big technical debt when you attach your code to a DI library. This is something that will be seen in every layer from your app, and almost every class. So be a wise person if you care about the code that you are providing.
@awaqar2
@awaqar2 Жыл бұрын
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 3 ай бұрын
Smart Sigma Kid #funny #sigma #memes
00:26
CRAZY GREAPA
Рет қаралды 2,7 МЛН
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 101 МЛН
Spot The Fake Animal For $10,000
00:40
MrBeast
Рет қаралды 194 МЛН
Koin 3.2 - Improving the Kotlin Developer Experience by Arnaud Giuliani
42:12
Make Your Code Clean With the SOLID Principles
18:24
Philipp Lackner
Рет қаралды 97 М.
Koin в Android на практике c MVVM
28:08
Тимофей Коваленко
Рет қаралды 23 М.
Should You Use Compose State or StateFlow in Your ViewModels?
13:59
Philipp Lackner
Рет қаралды 74 М.
Protocols vs ABCs in Python - When to Use Which One?
15:31
ArjanCodes
Рет қаралды 34 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 784 М.