yazazzello
05/13/2019, 1:14 PMPiotr Prus
05/16/2019, 6:04 AMval preferencesModule = module {
single { provideSettingsPreferences(androidApplication()) }
}
private const val PREFERENCES_FILE_KEY = "com.myapp.shared_preferences"
private fun provideSettingsPreferences(app: Application): SharedPreferences =
app.getSharedPreferences(PREFERENCES_FILE_KEY, Context.MODE_PRIVATE)
Benoit Duffez
05/16/2019, 10:36 AMby inject
at the top of the class, looks nicer anywayDavide Giuseppe Farella
05/19/2019, 5:35 PM->
= depends by ):
app -> feature modules
&
app -> "DImodules" module
&
DImodules -> all other modules ( feature and business )
In this way app takes a reference to all the koin modules from DImodules, without directly depend by them, but I don’t think this is an awesome solution.
Also I would like to invert the dependencies and let feature modules depends by app, but in this way I would have a dependency circle features -> app -> DImodules -> features
. Removing DImodules I wouldn’t know how to initialize other modules 🙄arnaud.giuliani
05/27/2019, 4:10 PMchavi
05/28/2019, 11:15 AMorg.koin.android.ext.android.setProperty
??Paulius Ruminas
05/29/2019, 2:03 PM// Register by KClass
private fun Module.single(
type: KClass<*>,
createdAtStart: Boolean = false,
override: Boolean = false
): BeanDefinition<*> {
val beanDefinition = BeanDefinition<Any>(
qualifier = null,
scopeName = null,
primaryType = type
).apply {
this.definition = {
val constructor = type.getFirstJavaConstructor()
val args = getArguments(constructor, this)
constructor.makeInstance(args)
}
this.kind = Kind.Single
}
declareDefinition(beanDefinition, Options(createdAtStart, override))
return beanDefinition
}
// Inject by KClass
private fun <T : Any> Application.inject(type: KClass<T>): Lazy<T> = lazy { getKoin().rootScope.get(type.java) }
// Module declaration
val myModule = module {
// findKClasses - returns List<KClass<*>>
findKClasses().forEach { single(it) }
}
We have classes that we need to resolve dynamically by KClass so that is why we need an ability to register them by KClass.
It works now but I wonder how much this code is prone to breaking changes in the future. Or is there an "official way" to achieve this?rg
06/03/2019, 9:45 AMkenkyee
06/07/2019, 9:32 AMdavid.bilik
06/09/2019, 6:03 PMarnaud.giuliani
06/11/2019, 4:02 PMarnaud.giuliani
06/13/2019, 3:59 PMgetViewModel
you can pass a KClass & the name is considered as the keyOve Stoerholt
06/17/2019, 11:25 AMyahyabayramoglu
06/18/2019, 12:47 PMEfe
06/20/2019, 9:44 AMEfe
06/20/2019, 9:45 AMLG
06/20/2019, 10:12 PMsingle { ClassA() }
// ClassA's using by inject
And
single { ClassA(get()) }
yahyabayramoglu
06/21/2019, 6:55 AMChainchelliah
06/23/2019, 4:08 PMSergio C.
06/23/2019, 9:04 PMby sharedViewModel()
? I have all the dependencies...Henning B
06/26/2019, 1:44 PMI/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'android.content.Context'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'android.content.Context'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
I/KOIN: +-- 'my.app.components.application.LocalizationHelper'
I/KOIN: +-- 'my.app.components.data.DataFormatter'
...
the actual output is around three times longer.Wilhelm Fitzpatrick
06/27/2019, 6:53 PMsmassive
07/01/2019, 7:15 AMKoinJavaComponent.get()
and too verbose to do a StandAloneContext.getKoin().koinContext.get()
, there are other options?gammax
07/05/2019, 4:17 PMMatt Thompson
07/09/2019, 2:51 PMLG
07/12/2019, 1:10 PMval remoteModule = module {
factory { CarRemoteRepositoryImpl() as CarsRepository }
}
How can I debug this from Koin core side?Sergio C.
07/14/2019, 12:03 PMSergio C.
07/14/2019, 12:23 PMval
?Marko Mitic
07/15/2019, 2:57 PMciriti
07/20/2019, 7:07 AMciriti
07/20/2019, 7:07 AMoleg_osipenko
07/21/2019, 2:51 PMnewApplication()
method inside the runner I submit my test Application, where I provide my test modulesciriti
07/21/2019, 3:24 PMarnaud.giuliani
07/22/2019, 8:21 AMciriti
07/22/2019, 8:50 AMarnaud.giuliani
07/22/2019, 3:46 PM