franztesca
08/01/2025, 8:22 PMinterface Dependency
@Inject
class DependencyImpl : Dependency
@Component
abstract class MyComponent {
abstract val dependency: Dependency
}
error
Cannot find an @Inject constructor or provider for: myapp.test.Dependency
am I missing something? 🤔
thank you colorPablichjenkov
08/01/2025, 8:44 PMeygraber
08/01/2025, 8:45 PMPablichjenkov
08/01/2025, 8:50 PMeygraber
08/01/2025, 9:04 PMevant
08/01/2025, 9:10 PMfranztesca
08/01/2025, 9:34 PMMap<[Interface], [Implementer @Inject class]>
should not be expensive in performance, or no? 🤔
My expectation is that 90% of the times the interface is going to have only one implementation in production, which can be overridden in tests. In such cases, auto-inferring the Implementation-Interface binding would save boilerplate code in the main source set. In case of multiple implementation (e.g. in the testing environment), then it would be easily detectable and would fallback to requiring explicit binding in the component. (e.g. If you override Http
from the auto-inferred RealHttp
to TestHttp
)Pablichjenkov
08/01/2025, 9:40 PMevant
08/01/2025, 9:43 PMralf
08/01/2025, 9:57 PM@ContributesBinding
annotation https://github.com/amzn/kotlin-inject-anvil/ralf
08/01/2025, 9:58 PMinterface Dependency
@Inject
@ContributesBinding(AppScope::class)
class DependencyImpl : Dependency
@MergeComponent(AppScope::class)
abstract class MyComponent {
abstract val dependency: Dependency
}
This should work now