Comments (9)
@congvc-apero Thank you for your reply.
So basically, you want to share the same SomeDependency instance to all ViewModel instances correct?
Within the scope of ParentActivity, yes. Exiting and re-entering ParentActivity creates a new instance of SomeDependency
. The scoped
dsl may be applicable in my case.
However, referring to
broke your code, but in a good way
I would like to determine:
- whether the change in factory behavior in this case is an intentional fix for erroneous Koin behavior in previous versions (factory in this exact case returned the same instance for sure in Koin versions 3.4.3 and 3.5.0 and probably in earlier versions as well)
- or the change in the behavior of factory in this case in version 3.5.3 is an accidental regression
This is important because I would like to know whether the behavior from previous versions in this situation will return in Koin 3.5.4 or this is the expected behavior.
from koin.
We're also seeing the same behaviour. Scoped viewmodels injected via Koin are now giving multiple instances whereas previously the same instance across the scope was expected.
from koin.
I observe similar erroneous behavior:
scope<ParentActivity> {
factory { SomeDependency(get()) }
viewModelOf(::FragmentXViewModel)
viewModelOf(::FragmentYViewModel)
}
In 3.5.0, FragmentXViewModel
and FragmentYViewModel
received the same SomeDependency
instance within the ParentActivity
scope - for example, in the situation of a transition from fragment X to fragment Y within the same ParentActivity
launch. In 3.5.3 they get different instances of SomeDependency
in the described situation.
from koin.
@dees91 I think v3.5.3 behavior is least astonishing because factory { }
will provide a new SomeDependency
instance each time a viewModel requests it
from koin.
@congvc-apero You are right that in this simplified snippet factory
works as you described, but I did not include important details about acitivity/fragment scope settings, that's why I prepared a repo with example that view models get the same instance of SomeDependency
within the ParentActivity
scope in 3.5.0 and they get a different instance in 3.5.3:
https://github.com/dees91/koinexperiment/tree/main/app/src/main/java/pl/deesoft/koinexperiment/experiment
3.5.0 | 3.5.3 |
---|---|
from koin.
@dees91 pardon me if I understand your usecase wrong. So basically, you want to share the same SomeDependency
instance to all ViewModel
instances correct? I tried ScopeSDL.scoped { }
dsl (in 3.5.3) and your code works fine, as it should. Indeed, factory { }
broke your code, but in a good way; it works as it should.
For clarify, here is CL I made
- factory { SomeDependency() }
+ scoped { SomeDependency() }
from koin.
Interesting how there are multiple behavioral/breaking changes going from 3.5.1 to 3.5.3. See also this issue I reported last month: #1738
A patch-level version update should not have breaking changes.
from koin.
@dees91 in that case, I'd like to keep track of the issue and see how it will be resolved.
from koin.
I would like to determine:
whether the change in factory behavior in this case is an intentional fix for erroneous Koin behavior in previous versions (factory in this exact case returned the same instance for sure in Koin versions 3.4.3 and 3.5.0 and probably in earlier versions as well)
or the change in the behavior of factory in this case in version 3.5.3 is an accidental regression
Here it's more a regression due to VM key build refactoring. IF I have proper tests/examples to reproduce to add to examples app, I can quickly patch it. Sorry for the break 🙏
from koin.
Related Issues (20)
- Seems like Koin Crash Again on androidContext 3.5.1 HOT 3
- Add bean/module destructor for Annotation-defined bean/module HOT 3
- Breaking change between koin-ktor versions 3.5.1 and 3.5.3 : can only install Koin in one embeddedServer instance HOT 13
- InstanceCreationException when passing mix of nullable and non-nullable parameters HOT 2
- [ksp] Unable to process:org.koin.compiler.BuilderProcessor HOT 4
- Write Normal Deprecation Messages With Replacement HOT 3
- checkKoinModules produce ConcurrentModificationException HOT 1
- missing watchosDeviceArm64 target HOT 1
- Avoid to leak dependencies
- [koin-core-coroutines] Pass a custom Dispatcher to the Koin coroutines engine HOT 2
- Missing "plus" operator for Lazy<Module> HOT 1
- The method with @composeable annotations is defined in the interface to get exceptions HOT 6
- Add Koin BoM in setup documentation HOT 1
- Android setup docs link's broken HOT 1
- [DOC] How to open and run Koin's project HOT 1
- Constructor DSL `named()` doesn't create qualifier and therefore doesn't work HOT 2
- activityViewModel cannot be created version core 3.5.3, android 3.4.0 . HOT 4
- Getting error when upgrading koin version or using bom HOT 1
- Online documentation links are broken HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from koin.