voben
03/30/2020, 8:32 PMprivate val viewModel by viewModel<MyViewModel>() { parametersOf(myParam) }
How do I pass a parameter when getting an instance of myViewModel in my test?
val vm = get<MyViewModel>()
james
04/02/2020, 8:39 AMonCreate
, I've got the following:
startKoin {
androidContext(this@MyApplication)
modules(listOf(
newsModule
))
}
and then my newsModule
looks like this:
val newsModule = module {
listOf(
networkModule,
uiModule
)
}
unfortunately, this doesn't work.. it builds, but everything provided inside networkModule
and uiModule
isn't accessible. how can I achieve this?pavi2410
04/03/2020, 8:48 PMmodule {
viewModel { ... }
...
}
My question is that whether the ViewModel is automatically scoped to the lifecycle of Fragment or not?
If not, then do I need to scope ViewModel to the Fragment like this?
module {
scope<MyFragment> {
viewModel { ... }
}
}
krtko
04/05/2020, 6:15 PMMatthieu Stombellini
04/06/2020, 4:51 PMInstance creation error : could not create instance for [Single:'<http://class.that.should.be|class.that.should.be>.injected.ClassName']: java.lang.IllegalStateException: No Koin Context configured. Please use startKoin or koinApplication DSL.
when using checkModules like this :
@Category(CheckModuleTest::class)
class ModuleCheck : AutoCloseKoinTest() {
val config = ...
val rules = ...
@Test
fun checkEpilinkModules() {
with(ClassThatProvidesModules(config, rules)) {
checkModules {
modules(moduleOne, moduleTwo, moduleTwo)
}
}
}
}
and launching the class with IntelliJ IDEA or gradle test
. Any ideas?kenkyee
04/07/2020, 11:18 PMamanda.hinchman-dominguez
04/08/2020, 2:21 AMyodgor777
04/10/2020, 6:57 PMyodgor777
04/11/2020, 4:00 PMRohil Chodankar
04/16/2020, 7:19 AMgetKoin() : Koin {
return //custom koin instance maintained as a HashMap
}
but now once we have updated to 2.1.5 , we are again facing the issue. Is there a particular change in scoping in the latest release ?ghosalmartin
04/17/2020, 3:42 PMinline fun <reified T> Module.networkService(
qualifier: Qualifier? = null,
createdAtStart: Boolean = false,
override: Boolean = false,
crossinline networkDefinition: () -> Class<T>
) = single(qualifier, override, createdAtStart) {
get<Retrofit>().create(networkDefinition.invoke())
}
yodgor777
04/19/2020, 6:23 PMyodgor777
04/19/2020, 6:46 PMquver
04/21/2020, 2:35 PMscope
and view models
I found https://github.com/InsertKoinIO/koin/issues/440#issuecomment-489583308
this solution but still have questions. Could you please hellp me.
I see that recommended way is to use.
private val viewModel: TabViewModel by viewModel { parametersOf(lifecycleScope.id) }
but what if I need global VM in many fragments with different lifecycle
What is best practice for this case. how I should create scope and that it between fragments?
UPD: googled laso sharedViewModel
but it shared VM based on Actiity. and I need to share based on main fragment.Tucker Barbour
04/26/2020, 11:47 AMstartKoin { modules() }
. Rather I'd like modules to be able to "install" other modules. This is how I'm used to structuring a project with Guice and maybe I'm just trying to apply this pattern where another might be better. Any help or guidance would be appreciated.Fatih
04/30/2020, 4:04 PMsewon
05/03/2020, 3:03 AMFeature Module A: create Koin for A
Feature Module B: create Koin for B
Common Feature Module: create Koin for Common. But Koin A, Koin B cannot get instances from Common Koin
Another way is each module define it’s own scope and define their own dependencies in there scope. By this way, they can use instances of shared library module and segregate their own dependencies. But to force feature module to use scope is not convenient. I should put scope before every get()
,inject()
call in modules.
Common Feature Module: create Koin
Feature Module A: create scopeA inside Common Koin
Feature Module B: create scopeB inside Common Koin
What I want is introducing parent - child Koin. In this concept, I can use KoinComponent
easily and can segregate each feature module.
Common Feature Module: create Koin for Common
Feature Module A: create Koin for A. set Koin for Common as parent Koin
Feature Module B: create Koin for B. set Koin for Common as parent Koin
Is this reasonable feature? Or is there any other better solution for this?Chintan Soni
05/08/2020, 4:14 AMYamko
05/08/2020, 5:35 PMcheckModules
in instrumentation test? I tried to do it, but constantly getting "No tests found". Mocking Context
isn't an option for me.amazingustav
05/08/2020, 10:40 PMApplicationContext
as parameter…
That’s my class:
class Foo(environment: ApplicationEnvironment) { ... }
That’s the class which calls Foo
:
class Bar(private val foo: Foo) { ... }
And that’s my KoinModuleBuilder
:
object KoinModuleBuilder {
fun modules() = listOf(module {
single {
Foo(get())
Bar(get())
}
})
}
And finally, that’s the error: org.koin.error.NoBeanDefFoundException: No compatible definition found for type 'ApplicationEnvironment'
Nikola Milovic
05/14/2020, 10:32 AMclass DrillsSelectionViewModel(
private val repository: DrillRepository,
private val io: CoroutineContext
) : ViewModel() {
val dispatchersModule = module {
// single<CoroutineContext>{Dispatchers.Main}
single<CoroutineContext>{<http://Dispatchers.IO|Dispatchers.IO>}
}
Now if I call get()
on the viewmodel, how can I specify whether I want the IO or the Main?Manuel Lorenzo
05/15/2020, 7:52 AMroberto
05/18/2020, 7:20 AMArchie
05/18/2020, 10:36 AMval viewModel by sharedViewModel<SomeViewModel>(from = { parentFragment!! })
but the from
seems to be removed in the current 2.1.5
version. Any reason why was it removed? and what to do instead?Deepti M
05/18/2020, 6:47 PMArchie
05/19/2020, 9:52 AMSomeDependency()
scoped to the lifecycle of the activity like so:
val someActivityModule = module {
scope<SomeActivity> {
scoped<SomeDependency> {
SomeDependencyImpl()
}
}
}
and then I have a fragment which needs that SomeDependency()
like so:
val someFragmentModule = module {
fragment {
SomeFragment(someDependency = get())
}
}
I was wondering how I would be able to get the depency correctly? Can anyone guide me? Thank you very much.Nikola Milovic
05/25/2020, 1:07 PMYamko
05/27/2020, 8:13 AMAndrew Steinmetz
06/02/2020, 6:16 AMKoinComponent
interface and using the get<SomeDependency>()
function. Now that I have compiled my multiplatform project for iOS with the latest Koin dependency, I was wondering since I am new to swift if there was any equivalent to doing the same thing to grab a dependency from swift?
This was the article I found with an example which seems to use property injection and doesn't actually create the repository as a single in iOS? https://johnoreilly.dev/posts/kotlinmultiplatform-koin/igor.wojda
06/02/2020, 7:45 PMNavManager
class that requires NavController
(Android Navigation Component) as collabolator.
What would be the best way to define Koin binding for NavManager
class? How instance to NavController
could be retrieved (from current Activity?)
class NavManager(private val navController: NavController) {
fun navigate(navDirections: NavDirections) {
navController?.navigate(navDirections)
}
}