Skip to content
0:00 / 0:00

#dependencyinjection#defaultarguments

Dead Simple Dependency Injection with Kotlin Default Arguments

Pairing with Duncan

4.5K subscribers • 15 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Duncan
  • An opinion. It argues one side of a question engineers disagree on.

Intermediate. Assumes working knowledge.

1.2K views4 years ago2 recommendations

Software designProgramming languagesKotlinDesign patternsSoftware architecture

Duncan demonstrates how to achieve simple dependency injection in Kotlin using default function arguments instead of heavy frameworks.

You don't need a framework to inject dependencies - DI is really just allowing dependencies to be specified rather than being baked in. In order to test our unreleased pricing code we want a version of the app that differs from the production version. Instead of introducing a framework to manage the dependencies, we just extract a function that builds the app from its components, and use default arguments for the production configuration. If you like this, you’ll probably like the book Java to Kotlin, A Refactoring Guidebook java-to-kotlin.dev.

Why it's here

2 people recommend this

What people say. Recommended as a clean, framework-free approach to dependency injection in Kotlin backend development.

u/dmcgin r/Kotlin • Recommends

Dead Simple Dependency Injection

u/unverifiable_userin r/Kotlin • Recommends

On “why does it seem that Kotlin isn't really taking off for backend development?”

I believe your are thinking too much about huge class hierarchies and complex object instantiation. This simple example was posted here recently: link to this video I could talk about such things for a long time, but it's probably not worth it here. People who want their DI (which isn't DI anymore, they are _frameworks_) will want their DI. I'm not completely against DI; if I find a need I suppose I'll go find one. The DI solution needs to be only a container and not an application framework with web servers, http clients, transaction managers, ORMs, and silly abstractions on top of other simple things. I may look at something like Koin, or go back and look at Guice again (but I would like the "more…