BLOG
BLOG
  • Design
  • Data
  • Discernment

We believe in AI and every day we innovate to make it better than yesterday. We believe in helping others to benefit from the wonders of AI and also in extending a hand to guide them to step their journey to adapt with future.

Know more

Our solutions in action for customers

DOWNLOAD

Featured Post

MENU

  • Visit Accubits Website.
  • Artificial Intelligence
  • Blockchain
  • Cloud Computing
  • Entertainment
  • Fintech

We have Dagger2. Then why Koin?

  • mm
    by Nikhil Seban on Mon Apr 27

Dagger2 is written in Java and Koin in Kotlin, and using both libraries in a Kotlin project should not be a challenge. However, implementing Koin in Java could be a little tricky. One notable information worth mentioning is that while Dagger2 is a fully acknowledged DI project, where as Koin is only described as a Service Locator.

In Android programming, handling dependency is a big concern. For the past few years, we are mainly using Dagger2 for the dependency injection. There is no doubt Dagger2 is one of the best available dependency injection framework now available. Now you can ask, as of now we have Dagger2 then why do we need to think about another framework?

Getting started with Julia language

Getting started with Julia language- Part 2, REPL and Packages

Read More

Before knowing the answer to the question, let’s understand what is Dagger2 and Koin.

Simply speaking… Dagger 2 is a dependency injection framework. It is based on the Java Specification Request (JSR) 330. It uses code generation and is based on annotations.

Dagger 2 uses the following annotations:

  • @Module and @Provides: define classes and methods which provide dependencies.
  • @Inject: request dependencies. Can be used on a constructor, a field, or a method.
  • @Component: enable selected modules and used for performing dependency injection

Dagger 2 uses generated code to access the fields and not reflection. Therefore it is not allowed to use private fields for field injection.

 

Koin is a practically sensible and realistically lightweight dependency injection framework for Kotlin developers. Written in pure Kotlin using functional resolution only: no proxy, no code generation, no reflection!

Koin is a Domain Specific Language, a lightweight container and a pragmatic API.

From the above statements, it is very clear both have the same functional requirements but the differences are very few isn’t it? To make it simple let’s go through simple real statistics which I observe.

Looking for reliable remote developers?

Choose from our pool of experienced developers

Get rate cards

 

koin vs dagger

Lines of code before and after compile.
 

koin vs dagger 2

Build statics.
 

koin vs dagger 2 performance

Google Search statics.

From the above statistical observations, it is very clear koin gains more points over Dagger2. Also from a developer perspective, I really do prefer koin more than Dagger2. Because implementing Dagger2 is a painstaking effort and moreover the debugging of Dagger2 (Ohh…) you will struggle. It may be a small issue, but because of the generated code, it will be a nightmare to fix it. And also learning Dagger2 is hard, so if someone joins your project or team he/she has to spend a lot of time on learning Dagger2.

Okay now, let’s answer why Koin?

  1. No Reflection.
  2. No Code generation.
  3. No need to write a lot of code just to do a simple injection.
  4. Very easy to integrate and maintain.
  5. Proxy free.
  6. No boilerplate code.
  7. Testing with Koin is very easy.

How to use Koin?

Just add this line to your Gradle.

// Stable Koin Version 
koin_version = "2.1.5"repositories {
 jcenter() 
}
 dependencies { 
// Koin for Android 
compile "org.koin:koin-android:$koin_version"
 // or Koin for Lifecycle scoping 
compile "org.koin:koin-android-scope:$koin_version" 
// or Koin for Android Architecture ViewModel 
compile "org.koin:koin-android-viewmodel:$koin_version" 
}

And create your module file, Go On… Happy Coding!

This article was originally published by Nikhil Seban on his Medium page.

We have Dagger2. Then why Koin?

By Nikhil Seban

Dagger2 vs Koin – Dagger2 is a dependency injection framework based on Java whereas Koin is a powerful Dependency injection framework for Kotlin.








What is the difference between Dagger2 and Koin?

Dagger2 is written in Java and Koin in Kotlin, and using both libraries in a Kotlin project should not be a challenge. However, implementing Koin in Java could be a little tricky. One notable piece of information worth mentioning is that while Dagger2 is a fully acknowledged DI project, whereas Koin is only described as a Service Locator. In Android programming, handling dependency is a big concern. For the past few years, we have been using Dagger2 for the dependency injection.

Click here to know more.

Why Koin?

Koin is a practically sensible and realistically lightweight dependency injection framework for Kotlin developers. Written in pure Kotlin using functional resolution only: no proxy, no code generation and no reflection.

What is the importance of Dagger 2?

Dagger 2 is a dependency injection framework. It is based on the Java Specification Request (JSR) 330. It uses code generation and is based on annotations. Dagger 2 uses generated code to access the fields and not reflection. Therefore it is not allowed to use private fields for field injection.

Click here to learn more.

Related Posts

Drive into stories worth discussing

  • mm
    Will Hashgraph Replace Blockchains?
    Rahul A R
  • mm
    What is a Predictable Gas Fee, and how it works?
    Rahul A R
  • mm
    How Blockchain Can Perfect Green Bonds?
    Rahul A R
  • mm
    How can Blockchain aid the Circular Economy Model?
    Rahul A R

ASK AUTHOR

mm
Nikhil Seban

A professional software engineer with 4 years experience. Specialised in building Mobile Applications and Native HAL. As a senior developer, ... Read more

Ask A Question
Error
Cancel
Send

Categories

View articles by categories

  • Blockchain
  • General

Subscribe now to get our latest posts

  • facebook
  • linkedin
  • twitter
  • youtube
All Rights Reserved. Accubits Technologies Inc