By default, Orbit will instantiate and activate Addressables using the default, empty constructor. Many times an Addressable will require some service or store for activation or its functional use.
Orbit supports a "bring your own DI container" model
The typical approach is to use constructor dependency injection, where dependencies are be supplied as constructor arguments.
class PlayerImpl(private val playerStore: PlayerStore) : AbstractActor(), Player {
... PlayerImpl code
}
To wire a DI container into Orbit, the addressableConstructor member of OrbitConfig can be replaced with a custom implementation of the AddressableConstructor interface. Below is an example
class KodeinAddressableConstructor(private val kodein: Kodein) : AddressableConstructor {
object KodeinAddressableConstructorSingleton : ExternallyConfigured<AddressableConstructor> {
override val instanceType = KodeinAddressableConstructor::class.java
}
override fun constructAddressable(clazz: Class<out Addressable>): Addressable {
val addressable: Addressable by kodein.Instance(TT(clazz))
return addressable
}
}
In this case, the KodeinAddressableConstructor requires a Kodein instance in its constructor. The instance can be supplied to the internal Orbit container through the containerOverrides member of OrbitConfig which will supply it automatically when the KodeinAddressableConstructor is created.