Hi Koin team, I have a question about @Provided w...
# koin
u
Hi Koin team, I have a question about @Provided with Koin Annotations + the compiler plugin. I’m working on a multi-module Clean Architecture setup like this: • feature -> domain <- data • domain:usecase contains plain use case classes • domain:usecase-di contains Koin DI definitions for those use cases • data:record contains repository implementations • app is the composition root My goal is to keep DI ownership in app / domain:usecase-di, and avoid making a feature DI module own or include the use case DI module directly. A simplified version of the setup looks like this:
Copy code
@Configuration("app")
@Module
class RecordFlowUseCaseDiModule {

    @Factory
    fun provideObserveEditableRecordUseCase(
        @Provided gameRecordRepository: GameRecordRepository,
    ): ObserveEditableRecordUseCase =
        ObserveEditableRecordUseCase(gameRecordRepository)

    @Factory
    fun provideSaveGameRecordUseCase(
        @Provided gameRecordRepository: GameRecordRepository,
    ): SaveGameRecordUseCase =
        SaveGameRecordUseCase(gameRecordRepository)
}

@Configuration("app")
@Module
@ComponentScan("co.tami.basketball.record.feature.record")
class RecordFeatureModule

@Configuration("app")
@Module
@ComponentScan("co.tami.basketball.record.data.record")
class RecordDataModule

@Module(
    includes = [
        CoroutineModule::class,
        RecordDataModule::class,
        RecordFlowUseCaseDiModule::class,
        RecordFeatureModule::class,
    ],
)
class AppModule
What I observed is: 1. If I remove @Provided from GameRecordRepository in domain:usecase-di, the compiler fails at A2 because domain:usecase-di cannot see the repository binding. 2. If I remove the Gradle dependency from feature:record to domain:usecase-di, the feature module cannot resolve the use case bindings during compile-time validation. 3. If RecordFeatureModule includes RecordFlowUseCaseDiModule, it works, but that feels wrong to me because it makes the feature module look like it owns the use case DI module. So my question is: Is using @Provided in this case the correct/recommended way to deal with cross-module visibility in A2 compile-time validation? Or is there a better pattern to keep: • domain:usecase plain • domain:usecase-di as the DI owner • app as the composition root • feature modules from owning the use case DI module Would the recommended solution be something like: • keeping @Provided as-is, • switching to typed startup / A3 full-graph validation, • reorganizing modules differently, • or some other Koin pattern? Any guidance would be really appreciated
➕ 1