Davide Giuseppe Farella
08/29/2020, 2:00 PMget<MyClass>()
get<MyClass> { parametersOf(MyParams(...)) }
William Lindblom
08/31/2020, 12:57 PMimport org.junit.experimental.categories.Category
import org.junit.jupiter.api.Test
import org.koin.core.parameter.parametersOf
import org.koin.dsl.module
import org.koin.test.AutoCloseKoinTest
import org.koin.test.category.CheckModuleTest
import org.koin.test.check.checkModules
interface First
class FirstImpl(a: String) : First
interface Second
class SecondImpl(a: First) : Second
@Category(CheckModuleTest::class)
internal class KoinTest : AutoCloseKoinTest() {
@Test
fun checkModules() {
val testModule = module {
single<Second> { SecondImpl(get()) }
single<First> { (foo: String) -> FirstImpl(foo) }
}
checkModules(parameters = { create<First> { parametersOf("hello") } }) {
modules(testModule)
}
}
}
Slackbot
08/31/2020, 3:36 PMnikolaymetchev
09/04/2020, 9:42 AM2.2.0-alpha-1
of koin. Is there any visibility as to when a proper release of 2.2.0 will be available?aipok
09/07/2020, 9:11 AMScopeActivity
and ScopeFragment
API’s…
• While using shared instance for activity and share it to all the fragments, it is not clear how to instantiate sharedViewModel
inside fragments that was created by activity. Looks like this API is not available anymore. I was able to achieve same result by using
scopeActivity?.let {
viewModel = it.getViewModel<SomeViewModel>()
}
is that the way to do this now?
• Another pain point is to inject instances using scopeActivity
into lazy properties. They are became nullable by default. Is it might be possible to use Fragment’s requireActivity()
method for getting requireScopeActivity
which is not nullable. Otherwise I have to insert ?
everywhere in my code then using property initialized like this
protected val imm by lazy {
scopeActivity?.get<InputMethodManager> {
parametersOf(requireActivity())
}
}
• In order to instantiate something that do not require scope from ScopeActivity
or ScopeFragment
should I use GlobalContext
or ScopeActivity.koin
calls? It is a bit confusing that default get
or inject
in ScopeActivity
and ScopeFragment
subclasses are trying to get instance from its scope
. From what I have, usually I’m getting some factory instances by default without any scope
and some specific (more like a rare) scoped injections. I would prefer to have scope.get
/ scope.inject
and default get
/ inject
to be koin.get
koin.inject
. Not sure might be thats only my opinion and other developers are using it opposite.
Fill free to open discussion and drop your comments. I would happy to hear any suggestions or ways to use Koin scope
system or sharedViewModel
definition.
Thanks!arnaud.giuliani
09/09/2020, 7:33 AM3.0.0-alpha-3
is out 👍arnaud.giuliani
09/09/2020, 9:30 AM3.0.0-alpha-4
Javier
09/09/2020, 9:45 AMnikolaymetchev
09/10/2020, 5:48 PMMark
09/13/2020, 2:16 AMPeter Farlow
09/14/2020, 9:01 PMaipok
09/16/2020, 12:41 PMoverride val scope: Scope by lazy { koin.createScope(scopeID, getScopeName(), this) }
in my child fragment which extends from ScopeFragment
. For some reason it gives me else condition and exception NoScopeDefFoundException
from onViewCreated
method.
val scopeDefinition = _scopeDefinitions[qualifier.value]
return if (scopeDefinition != null) {
val createdScope: Scope = createScope(scopeId, scopeDefinition, source)
_scopes[scopeId] = createdScope
createdScope
} else {
throw NoScopeDefFoundException("No Scope Definition found for qualifer '${qualifier.value}'")
}
Should I declare each fragment scope in my module before I can use or why I could get this error in 2.2.0-beta-1
version?
Also it seem to call createScope
and fail in onViewCreated
because of this line
koin._logger.debug("Open fragment scope: $scope")
in ScopeFragment
Update: after a bit of tries. If I declare scope for a fragment like this
scope(named<ChildFragment>()) { }
It still not work, but I remember it was mentioned that empty declarations will not be allowed… so it works it I declare something scoped
scope(named<ChildFragment>()) {
scoped { (activity: BaseActivity) -> CustomTabsHelper(activity) }
}
But this is very weird that I have to declare scope before the fragment createScope
. My assumption was that each ScopeFragment
is able to create its own scope and I can use that scope anytime I need it. Since all my fragment as extended from the same BaseFragment or similar. This is very unusable since I can’t extend from ScopeFragment
only on some of them.
From other hand declaring useless scopes in modules for each and every fragment I have this is even more work. Not sure what was the idea behind this change. With lifecycle it was much easier (like is it if you need it or just skip it).
As usual any feedback or discussions are welcome 😄
Koin is the best anyway 🤟willyrs
09/18/2020, 8:23 AMarnaud.giuliani
09/25/2020, 1:31 PMcoroutinedispatcher
09/27/2020, 5:39 PMMainActivity
that implements MainActivityInteraction
interface, and many fragments need this interface in order to communicated with the MainActivity
, using koins fragmentFactory
, is that achievable? I cannot actually do:
single {MainActivity()} binds arrayOf(MainActivityInteractions::class)
fragment {BlaBlaFragment(get())} // should get the interface above
Because it's dangerous. Short question, how can I achieve interface communication between fragments and a single activity with koinarnaud.giuliani
09/28/2020, 9:38 AMJoaquim Ley
09/29/2020, 1:51 PMby viewModel()
or wtv it suits you, you could even inject()
but on Swift seems like we don't have access to Koin's sugar.
--
Summarising:
View wants to create a ViewModel <- UseCase <- Repository <- RemoteApi
Note: '<-' Depends onsloydev
10/07/2020, 2:52 PMsingle
.
I've isolated the issue to a concurrency bug in SingleInstanceFactory
. I have an (ugly) test reproducing it, and a possible solution. It's tricky because the probability of happening is very low, but it happens ^^'
@arnaud.giuliani would you like me to open a PR? Or do you prefer to discuss it here before?sahil Lone
10/08/2020, 8:30 AMtarek
10/09/2020, 1:32 PMdagomni
10/09/2020, 3:46 PMnrobi
10/12/2020, 10:24 AMkoin 2.2.0-rc-2
with kotlin 1.4.10
. More details in threadSaul Wiggin
10/12/2020, 10:52 AMUnable to start activity ComponentInfo{com.example.cakesapimvvm/com.example.cakesapimvvm.MainActivity}: org.koin.core.error.InstanceCreationException: Could not create instance for [Factory:'com.example.cakesapimvvm.viewmodel.CakeListViewModel']
arnaud.giuliani
10/13/2020, 11:55 AMnrobi
10/14/2020, 10:17 AMgetViewModel()
in a composable, where the parameters of the vm are subject to change?Krystian Rybarczyk
10/14/2020, 2:44 PMwithTestApplication({ module() }) {
is executed. The error is:
No definition found for class:'com.alpha.CoolService'. Check your definitions!
org.koin.core.error.NoBeanDefFoundException
The bean is definitely there. As I mentioned it works fine in the other test suite. When I stopped there with the debugger there were no beans to be found indeed. CoolService
is just the first been that I try to retrieve with get()
. It seems that the context is somehow screwed up. Could it be that the separate ktor test suites are messing up each others Koin contexts?tieskedh
10/15/2020, 9:34 AM@Composable
inline fun <reified T : ViewModel> viewModel(
qualifier: Qualifier? = null,
noinline parameters: ParametersDefinition? = null
): Lazy<T> {
val owner = ViewModelStoreOwnerAmbient.current.viewModelStore
return remember {
KoinContextHandler.get().getViewModel(
owner = { owner },
qualifier = qualifier,
parameters = parameters
)
}
}
Saul Wiggin
10/15/2020, 10:17 AMbinding.viewmodel = viewModel
where previously the error was Koin not correctly configured.Javier
10/19/2020, 11:55 AMsebastien.rouif
10/20/2020, 12:10 PMscoped { (mapId: String) -> MapIdProvider(mapId = mapId) }
but I need to call myScope.get { parametersOf(getMapId()) }
directly after the scope creation so that the mapId is passed to the bean definition. It seems that Scope
class can also have some parameters so I tried
koin.createScope<RootActivityScopeKey>().also {
it.addParameters(parametersOf(getMapId()))
}
but then I get Can't get injected parameter #0 from DefinitionParameters[] for type 'java.lang.String'
I tried removing the definition in the scope adding the
koin.createScope<RootActivityScopeKey>().also {
it.addParameters(parametersOf(MapIdProvider(getMapId())))
}
but no success either.
Is there a better way to inject that MapIdProvider
? note that MapIdProvider
is just a dataClass that holds the mapId