Reputation: 237
I need to assign a new value to my single Koin variable, but Koin does not allow to use var on the injected variable...
private val userAssets: UserAssets by inject()
How set value on userAssets? Or have another thing to do to make UserAssets Singleton?
val dataModule = module {
factory {
RetrofitBuilder(
androidContext()
)
}
single { LoginCredential() }
single { UserAssets() }
}
Upvotes: 1
Views: 2518
Reputation: 155
Hi you can try with Declaring injection parameters, here the reference.
In the module you can write:
single { value : String -> UserAssets(value) }
then you should be able to use inject
val userAssets : UserAssets by inject { parametersOf("value") }
Upvotes: 1
Reputation: 2415
I personally do not use Koin, so I can not verify it, but Koin also provides a way to directly retrieve an instance with get()
. So in your case:
private var userAssets: UserAssets = get()
Might work so you can later reassign it, at least that is what I understand from their their documentation.
Upvotes: 3