I have a class that takes a `clockNow: () -> Insta...
# koin
o
I have a class that takes a
clockNow: () -> Instant
parameter. To inject it, I provide a
single<() -> Instant>
. It works but I get a warning:
Type is not declared in Koin modules: () -> Instant
Copy code
val myModule = module {
    single<() -> Instant> { Clock.System::now }

    singleOf(::TaskRepository)
}
Is it expected? Can I do better? (to declutter, I introduced a type alias
typealias NowProvider = () -> Instant
but it doesn't change anything)
p
Try using a
fun interface
instead of a plain lambda.
Copy code
fun interface NowProvider {
    fun now(): Instant
}

val myModule = module {
    single<NowProvider> { NowProvider { Clock.System.now() } }
    single<NowProvider> { NowProvider(Clock.System::now) }

    singleOf(::TaskRepository)
}
👍 1
o
Yes, this would remove the warning indeed. Is it expected to have the warning with the lambda though? It surprises me.