Comments (5)
You can (at the moment), also sneak in and change the internal key yourself.
public var sharedClass: Factory<SharedClass> {
self(key: "sharedClassB") { .init() }.singleton
}
from factory.
So yes. You're creating the same class with the same name in multiple modules with a singleton scope. Singletons use a mashup of the factory function name and the type name as cache key. So basically you're using the same identical function name AND the same identical class name--even though they're actually different types--in different modules. So the name is found is found in the singleton cache but the actual type is different so it's recreated and recached.
I'll look to see what I can do, but as discussed in the documentation singletons are somewhat problematic to use in your code. Given your example of simply using the shared container instance, you'd be better off simply specifying the scope as .cached.
See the section on singletons in the Testing documentation.
from factory.
Thanks for the info. I failed to notice the function name also affects the cache key, which would also be acceptable to change.
Given my scenario, I have a wrapper for UserDefaults with the same name / functionality, but still would be unique singletons with different properties. So would be nice to consider the module name also in the cache key. Also in cases of third party packages that use Factory (in the rare occasion they may collide).
I would close this, since there is a workaround / preferred usage.
from factory.
Will be fixed in 2.1.4
from factory.
Fixed.
from factory.
Related Issues (20)
- Concurrency-safe warnings when `strict-concurrency` is set to `complete` HOT 2
- Please add action to test linux build HOT 8
- Can't mock`.cached` scope factory HOT 5
- Equivalent of Resolver implement for multiple protocol HOT 2
- Typo in SwiftUI docs? HOT 1
- Support @Observable macro HOT 5
- Typo in code example (Modular Development) HOT 1
- Crash due to concurrent access to cache HOT 8
- Unable to integrate Factory via CocoaPods on Xcode 14.3.1 (14E300c) HOT 2
- Overriding registration in preview HOT 4
- Promised ParameterFactory HOT 1
- Could not find module 'Factory' for target 'x86_64-apple-ios-simulator'; found: arm64-apple-ios-simulator, at HOT 1
- MainActor issue with ObservableObject's HOT 1
- When using context runtime arguments in an async context I get unreliable behaviour HOT 5
- Resetting scopes HOT 2
- Tiny bug: promised is not forwarding the file and line parameters to triggerFatalError. HOT 1
- onPreview modifier breaks shared scope HOT 2
- Issue with factory registrations in preview HOT 3
- @InjectedLazyObject HOT 1
- Multiple previews and resolving different values for a singleton HOT 1
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 factory.