你好我刚学 Koin,这个 Dagger2 类在 Koin 2.0 中如何提供?
@Singleton
open class AppExecutors(private val diskIO: Executor, private val networkIO: Executor, private val mainThread: Executor) {
@Inject
constructor() : this(
Executors.newSingleThreadExecutor(),
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1),
MainThreadExecutor())
fun diskIO(): Executor {
return diskIO
}
fun networkIO(): Executor {
return networkIO
}
fun mainThread(): Executor {
return mainThread
}
private class MainThreadExecutor : Executor {
private val mainThreadHandler = Handler(Looper.getMainLooper())
override fun execute(command: Runnable) {
mainThreadHandler.post(command)
}
}
}
我试过这个:
single<AppExecutors> { AppExecutors(
Executors.newSingleThreadExecutor(),
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1),
AppExecutors.MainThreadExecutor())
}
但是AppExecutors.MainThreadExecutor()
是私人的。公开它是唯一的解决方案吗?