Refactor: Replace kotlin-inject with Metro for dependency injection#155
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #155 +/- ##
==========================================
- Coverage 70.08% 69.79% -0.30%
==========================================
Files 145 144 -1
Lines 8107 8140 +33
Branches 1032 1038 +6
==========================================
- Hits 5682 5681 -1
- Misses 1912 1946 +34
Partials 513 513
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:
|
24eeaf7 to
2cafd19
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.
2cafd19 to
853b49c
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.