Metro station is a Kotlin compiler plugin built on Metro to simplify members injection for Android components.
⚠️ This repo is pretty much a wip, there is no release available yet.
There are two main annotations located in :runtime - @MetroStation and
@StationEntry, they're analogous to metro's @DependencyGraph and
@GraphExtension.
Annotate @MetroStation on a target where you want a standalone dependency graph.
For example:
@MetroStation
class MyActivity
// Generated FIR structure by metro-station
@DependencyGraph(scope = MyActivity::class)
interface MyActivityDependencyGraph {
fun inject(target: MyActivity)
@DependencyGraph.Factory
interface Factory {
fun create(@Provides target: MyActivity): MyActivityDependencyGraph
}
}We plan to generate injection points automatically for known Android components, like Activities, Fragments, Views, Broadcast Receivers and Workers because we know when they should be injected. But this is yet to be implemented. (see #22)
Annotate @StationEntry on a target where you want a graph extension, and specify the scope of the dependency graph in
parentScope where you want to contribute the graph extension.
For example:
@StationEntry(parentScope = AppScope::class)
class MyActivity
// Generated FIR structure by metro-station
@GraphExtension(scope = MyActivity::class)
interface MyActivityGraphExtension {
fun inject(target: MyActivity)
@ContributesTo(scope = AppScope::class)
@GraphExtension.Factory
interface Factory {
fun create(@Provides target: MyActivity): MyActivityGraphExtension
}
}ℹ️ There are more features yet to come:
The Kotlin compiler test framework is set up for this project.
To create a new test, add a new .kt file in a compiler-plugin/testData sub-directory:
testData/box for codegen tests and testData/diagnostics for diagnostics tests.
The generated JUnit 5 test classes will be updated automatically when tests are next run.
They can be manually updated with the generateTests Gradle task as well.
To aid in running tests, it is recommended to install the Kotlin Compiler DevKit IntelliJ plugin,
which is pre-configured in this repository.