FinWhaleX VS banks

Banks are credit organizations that exist in any country of the world. And many of us are clients of these banks. Here we pay bills, receive transfers, take loans… And, yes, this is an established…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Setting up Koin 2.0.1 for Android

This set of examples builds up to many parts, check them out too:

This post is aimed to help you get up and running with Koin 2.0.1. You’ll have to look elsewhere for in-depth DI guides.

Check out the second part for implementing Retrofit 2.6.0 with coroutines support here:

Add the following dependencies in your project:

Next up, override the application class, it’s where Koin is initialised. Remember to update the AndroidManifest with the new Application path. Override the onCreate lifecycle method and initialise Koin as follows.

Context is provided through the androidContext invocation. Update the list of modules with those declared in your project.

Above shows an example of field injections for an activity. Fragments can be injected similarly to any other dependency. Note that the “inject()” function is not available outside of KoinComponents.

View models are injected as field injections. First create your view model and it’s respective module.

That’s it for the basics. You can find the source code from GitHub, feel free to comment and suggest further topics.

Note that the following posts on this topic will build on the same source code, so everything might not look exactly like it’s here!

More info on Koin can be found from the official docs:

Check out the next parts in the series:

Add a comment

Related posts:

Stages of Beach

My body has never been what you’d call ‘beach ready’ but then, I’ve never cared. See the weight on my arms, the gut, the breasts. Roll up, roll up an see this unholy mess that I am. At stage one, I…

Tips dan Trik Cara Menabung Uang Dengan Benar

Pada artikel kali ini saya akan menjelaskan tips dan trik cara menabung uang. Namun, sebelum itu, tahukah kamu apa itu uang ?. Simak penjelasannya berikut ini. Dalam ilmu ekonomi tradisional biasanya…

Exploring The Unknown

As we try to carve out new solutions to both old and new problems, seek out new insights, explore the implications of asking new questions and imagine questions we don’t yet know to ask. It is of…