Skip to content
프로젝트

소개

Kotlin을 위한 멀티플랫폼 컴파일 타임 의존성 주입 프레임워크

개발 도구

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
+2
in 15 days
+9
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

🚇 Metro

A compile-time dependency injection framework for Kotlin Multiplatform, powered by a Kotlin compiler plugin.

Maven Central Kotlin Build Status License


What is Metro?

Metro is a compile-time dependency injection framework that combines the best of Dagger, Anvil, and kotlin-inject into one cohesive solution.

Key Features:

  • ✅ Compile-time validation – Catch dependency graph errors during compilation, not at runtime
  • 🧩 FIR/IR code generation – No KAPT or KSP required, just a Kotlin compiler plugin
  • 🎯 Kotlin-first API – Inspired by kotlin-inject with top-level function injection and optional dependencies
  • 🗡️ Dagger-esque runtime – Lean generated code with familiar patterns
  • ⚒️ Anvil-style aggregation – @ContributesTo, @ContributesBinding, and more
  • 🌐 Multiplatform – Supports JVM, JS, Wasm, and Native targets
  • 💡 Helpful diagnostics – Detailed error messages with actionable suggestions
  • 🔗 Advanced interop – Migrate incrementally from Dagger, kotlin-inject, or Guice
  • ⚡️ Fast - At build time, at runtime

Quick Start

1. Apply the Gradle plugin:

plugins {
  id("dev.zacsweers.metro") version "<version>"
}

2. Define a dependency graph:

@DependencyGraph
interface AppGraph {
  val repository: UserRepository

  @Provides
  fun provideApi(): Api = ApiImpl()
}

@Inject
class UserRepository(private val api: Api)

3. Create and use the graph:

val graph = createGraph<AppGraph>()
val repository = graph.repository

Documentation

📚 zacsweers.github.io/metro

Topic
Installation Setup and configuration
Dependency Graphs Define and create graphs
Provides Provider functions and properties
Injection Types Constructor, assisted, and member injection
Scopes Scoping and lifecycle management
Coroutines Support Suspend bindings and deferred initialization
Aggregation Anvil-style contributions across modules
Interop Dagger, kotlin-inject, and Guice compatibility
Performance Build and runtime performance
Compatibility Supported Kotlin versions
FAQ Frequently asked questions
API Docs Generated KDocs

Supported Platforms

Metro supports JVM, Android, JS, Wasm, and Native targets. The compiler plugin works with all Kotlin Multiplatform project types.

See the multiplatform docs for full details.


License

Copyright (C) 2025 Zac Sweers

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

관련 프로젝트 살펴보기

불러오는 중…