Closed santimattius closed 3 weeks ago
Yes I like your proposal. I tunned it like this:
@KoinExperimentalAPI
interface KoinStartup {
/**
* startKoin with AndroidX startup Initializer
* @see startKoin function
*/
@KoinApplicationDslMarker
fun onKoinStartup() : KoinAppDeclaration
}
class KoinInitializer : Initializer<Koin> {
@OptIn(KoinExperimentalAPI::class)
override fun create(context: Context): Koin {
return if (context is KoinStartup){
startKoin(context.onKoinStartup()).koin
} else error("Can't start Koin configuration on current Context. Please use KoinStartup interface to define your Koin configuration with.")
}
override fun dependencies(): List<Class<out Initializer<*>>> {
return emptyList()
}
}
And yes, documentation must be added to extend it to allow precise some dependency on it.
@santimattius do you have any feedback regarding impact with https://developer.android.com/google/play/integrity?
PR in follow: https://github.com/InsertKoinIO/koin/pull/2039
Thanks @arnaudgiuliani! Regarding app integrity, I was reviewing the issue but I did not find any information on what could cause the error when app integrity is activated.
thanks @santimattius 👍
I have reviewed the new Koin startup implementation using App Startup and I think it's excellent that they have added this support. Some time ago I wrote a post about it "Koin Startup Extension: Configuring Koin using App Startup in Android".
What caught my attention, and the reason I'm addressing this here, is the KoinStartup object. This is used to maintain the reference of the Koin declaration, and the documentation indicates that we should call the onKoinStartup method in the init of our Application class. I think we could improve it by using the same strategy that WorkManager employs. Below, I share some code to visualize this idea.
First, we would need an interface to infer the declaration when the Initializer is executed
We could also name it KoinStartup.
Then, we would have the implementation in our Application class:
Once we have the implementation of
KoinDeclaration
in our Application class, we could perform the following verification in our InitializerAt this point, we could also configure the
androidContext
, ensuring that it's always initialized.Documentation
While the koin-startup functionality is still experimental, it would be beneficial to include information on how to use Koin in other initializers. This is especially relevant since App Startup allows specifying the dependency order. An illustrative example could be:
I hope these ideas and suggestions are helpful. If you have any comments or additional proposals, please feel free to share them.