Ktor Series: Dependency Injection using Koin — Ktor API Project

Vishwas Trivedi
4 min readDec 11, 2023

Another article in the Ktor Series, let’s go!

This is the second article in “Ktor Series”, in this article we are going to take a look at how we can use Koin to inject dependencies in our API project.

Well, it’s kinda true that dependency injection makes your code easy to test but let’s start with the basics first and take a look what what we are talking about.

What is dependency injection?

Dependency injection(DI) is a programming technique in which an object or function receives other objects or functions that it requires, as opposed to creating them internally. Dependency injection aims to separate the concerns of constructing objects and using them, leading to loosely coupled programs.

Or as one of my friend puts it: it is just a pass by reference instead of pass by value. The only catch is, we use interfaces to make it loosely coupled.
(Well, he is not wrong)

Now that we know about the basic of the DI, let’s understand what is Koin?

What is Koin?

The koin-ktor module/plugin is dedicated to bring dependency injection for Ktor.

--

--

Vishwas Trivedi

I am an accomplished Software Engineer/ Project Manager with 8.5 years of technical experience in driving successful software development teams.