koin-guide

Configure Koin modules for dependency injection in Kotlin/Android apps.

8|1|Updated Jun 12, 2018
One-click install
npx skills add https://github.com/SheTieJun/BaseKit --skill koin-guide
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: koin-guide
Source: https://github.com/SheTieJun/BaseKit/tree/main/.trae/skills/koin-guide
Command: npx skills add https://github.com/SheTieJun/BaseKit --skill koin-guide

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Solves the problem of boilerplate dependency injection in Kotlin/Android by using Koin.

Core Features & Use Cases

  • Module-based configuration: Define dependencies with module blocks and scope rules.
  • Single, Factory, and ViewModel injections: Use single for singletons, factory for new instances, and viewModel for Android architecture components.
  • Use Case: Imagine an Android app with a repository, a networking layer, and a ViewModel; Koin wires dependencies with minimal boilerplate and supports named qualifications and scopes.

Quick Start

To set up Koin in an Android app, add the dependencies to your Gradle files, create a MyApp class that starts Koin, declare modules, and inject dependencies into Activities or ViewModels.

Frequently Asked Questions about koin-guide

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

FAQPage Schema
How do I set up dependency injection in Kotlin Android without boilerplate?

Set up dependency injection in Kotlin Android by using Koin modules to define dependencies, configuring single, factory, and viewModel scopes, and injecting via by inject() to eliminate manual boilerplate. Start Koin in your Application class to wire repositories and networking layers cleanly.

How does Koin handle ViewModel injection for Android architecture components?

Koin handles ViewModel injection by providing a dedicated viewModel keyword within module definitions, allowing you to directly integrate Android architecture components and inject dependencies into ViewModels cleanly without factory boilerplate.

Can I use Koin for modular dependency injection with scopes and qualifiers?

Yes, Koin supports modular dependency injection with named qualifiers and specific scope rules. You can define module blocks to separate dependencies and apply scope rules to manage instance lifecycles across different Android app modules.

When should I use single vs factory scopes in Koin modules?

Use the single scope when you need shared singleton instances throughout the app lifecycle, and use the factory scope when you need a new instance created every time it is injected, ensuring proper dependency management for your Kotlin Android architecture.

What is the best way to start Koin in an Android app?

The best way to start Koin in an Android app is to add the Gradle dependencies, create a custom Application class to initialize Koin, declare your modules, and then use by inject() or viewModel() in your Activities and ViewModels to retrieve dependencies.