Skip to content

Refactor: Replace kotlin-inject with Metro for dependency injection#155

Open
Rolf-Smit wants to merge 1 commit intomainfrom
feature/refactor-dependency-injection-to-metro
Open

Refactor: Replace kotlin-inject with Metro for dependency injection#155
Rolf-Smit wants to merge 1 commit intomainfrom
feature/refactor-dependency-injection-to-metro

Conversation

@Rolf-Smit
Copy link
Copy Markdown
Contributor

@Rolf-Smit Rolf-Smit commented Apr 23, 2026

Upside:

  • Metro is a Kotlin compiler plugin, so it generates .class files directly during IR transformation rather than producing source files like KSP. This removes the need for the KSP plugin and seems to also eliminate per iOS target wiring in the build script, this is nice.

Downside:

  • @Inject on top-level functions works at compile time, but the generated types are not resolved by the IDE ("Unresolved reference" errors). Wrapper classes with @Inject on the constructor and a @Composable operator fun invoke() seem to be the recommended approach to avoid this. However, this is not ideal as it adds boilerplate (see: https://zacsweers.github.io/metro/latest/installation/#ide-support).
  • Metro graphs cannot have constructor parameters, and platform specific modules cannot extend the shared graph with additional bindings (only the reverse direction is supported via @GraphExtension it seems). So platform dependencies must be constructed manually. Currently there is only one (PlatformFileDataSource), but if more are added this might get messy. kotlin-inject avoided this through component inheritance.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 1.92308% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.37%. Comparing base (4baccdf) to head (2cafd19).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tech/app/abysner/presentation/MainNavController.kt 0.00% 15 Missing ⚠️
...abysner/presentation/screens/planner/PlanScreen.kt 0.00% 14 Missing ⚠️
...er/presentation/screens/DiveConfigurationScreen.kt 0.00% 5 Missing ⚠️
...app/abysner/presentation/screens/SettingsScreen.kt 0.00% 5 Missing ⚠️
...s/terms_and_conditions/TermsAndConditionsScreen.kt 0.00% 5 Missing ⚠️
.../abysner/presentation/screens/about/AboutScreen.kt 20.00% 3 Missing and 1 partial ⚠️
.../kotlin/org/neotech/app/abysner/di/AppComponent.kt 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #155      +/-   ##
==========================================
- Coverage   51.55%   51.37%   -0.19%     
==========================================
  Files         139      138       -1     
  Lines        7956     7517     -439     
  Branches      909      915       +6     
==========================================
- Hits         4102     3862     -240     
+ Misses       3508     3310     -198     
+ Partials      346      345       -1     
Flag Coverage Δ
domain 76.29% <ø> (-0.21%) ⬇️
presentation 45.73% <1.92%> (-0.43%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rolf-Smit Rolf-Smit force-pushed the feature/refactor-dependency-injection-to-metro branch from 01ff314 to 24eeaf7 Compare April 23, 2026 11:51
Upside:
- Metro is a Kotlin compiler plugin, so it generates .class files directly during IR transformation rather than producing source files like KSP. This removes the need for the KSP plugin and seems to also eliminate per iOS target wiring in the build script, this is nice.

Downside:
- `@Inject` on top-level functions works at compile time, but the generated types are not resolved by the IDE ("Unresolved reference" errors). Wrapper classes with `@Inject` on the constructor and a `@Composable operator fun invoke()` seem to be the recommended approach to avoid this. However, this is not ideal as it adds boilerplate (see: https://zacsweers.github.io/metro/latest/installation/#ide-support).
- Metro graphs cannot have constructor parameters, and platform specific modules cannot extend the shared graph with additional bindings (only the reverse direction is supported via `@GraphExtension` it seems). So platform dependencies must be constructed manually. Currently there is only one (`PlatformFileDataSource`), but if more are added this might get messy. kotlin-inject avoided this through component inheritance.
@Rolf-Smit Rolf-Smit force-pushed the feature/refactor-dependency-injection-to-metro branch from 24eeaf7 to 2cafd19 Compare April 23, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants