kotlin-context-di

Implement manual dependency injection for Kotlin using AppDependencies contracts and SystemContext implementations.

14|2|Updated Sep 10, 2022
One-click install
npx skills add https://github.com/anderssv/the-example --skill kotlin-context-di
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-context-di
Source: https://github.com/anderssv/the-example/tree/main/skills/practices/kotlin-context-di
Command: npx skills add https://github.com/anderssv/the-example --skill kotlin-context-di

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you replace framework-based dependency injection with a type-safe manual wiring approach that stays easy to test and reason about.

Core Features & Use Cases

  • Interface-first dependency contracts: Define an AppDependencies interface with nested grouping interfaces so components declare exactly what they need.
  • Production wiring with SystemContext: Build eager, explicit production wiring without open classes or lazy, keeping initialization transparent.
  • Standalone test wiring with SystemTestContext: Create fresh, self-contained test contexts that use fakes and avoid inheritance between production and test code.

Quick Start

Ask the AI to generate a manual DI setup using AppDependencies, SystemContext, and SystemTestContext for your Kotlin service layer and route handlers.

Frequently Asked Questions about kotlin-context-di

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up manual dependency injection in Kotlin without a DI framework?

Manual dependency injection in Kotlin can be set up by defining an interface-first AppDependencies contract and wiring components through separate SystemContext and SystemTestContext implementations. This approach keeps initialization transparent without relying on open classes or lazy properties.

What is the best way to wire Kotlin apps for testability without framework lifecycle objects?

The best way to wire Kotlin apps for testability is using interface-first dependency contracts where controllers and route functions accept dependency interfaces rather than framework lifecycle objects. Fresh per-test contexts with in-memory fakes ensure standalone test wiring.

Can I use manual DI with Ktor route handlers and avoid inheritance between production and test code?

Yes, manual DI works with Ktor by passing dependency interfaces to route functions and using a standalone SystemTestContext. This creates fresh, self-contained test contexts using fakes, completely avoiding inheritance between production and test code.

Does manual dependency injection in Kotlin require open classes or lazy initialization?

No, manual dependency injection in Kotlin does not require open classes or lazy initialization. It uses type-safe eager initialization with explicit production wiring, keeping the dependency setup transparent and straightforward.

How do I override specific dependencies in a Kotlin test context without rewriting the whole setup?

You can override specific dependencies in a Kotlin test context using delegation-based partial overrides. The SystemTestContext utilizes covariant override inference with inner grouping classes, allowing targeted concrete fake access without rewriting the entire wiring setup.