Refactor: Replace kotlin-inject with Metro for dependency injection#155
Open
Refactor: Replace kotlin-inject with Metro for dependency injection#155
Conversation
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
01ff314 to
24eeaf7
Compare
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.
24eeaf7 to
2cafd19
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upside:
Downside:
@Injecton top-level functions works at compile time, but the generated types are not resolved by the IDE ("Unresolved reference" errors). Wrapper classes with@Injecton 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).@GraphExtensionit 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.