Comments (6)
Glad you're enjoying Factory. (And the documentation. ;) )
Something similar to this is kicking around over in Resolver, but I'm still not totally convinced of the general need for such a thing. Your associated type and sugar make things type safe, but also makes it a little clunky to setup.
I think I need to kick it around in my head for awhile and see what comes up.
Just noting that your code has a significant problem in that you're storing a factory in an object that belongs to a container. Factory's are designed to be short-lived entities for several reasons, but one of them is that they contain a hard reference to their container so they can resolve when needed.
In short there's a retain cycle there. You may need to consider something like the following with key paths...
func autoRegister() {
tag(\MyContainer.processor1, as: pipelineProcessor)
tag(\MyContainer.processor2, as: pipelineProcessor)
}
Thanks for the work, regardless.
from factory.
Then again, there's this...
extension Container {
static var processors: [KeyPath<Container, Factory<Processor>>] = [
\.processor1,
\.processor2,
]
func processors() -> [Processor] {
Container.processors.map { self[keyPath: $0]() }
}
var processor1: Factory<Processor> { self { Processor(name: "processor #1") } }
var processor2: Factory<Processor> { self { Processor(name: "processor #2") } }
}
Anyone is also free to add their own extensions and append to the array as needed.
from factory.
Seems like a really clean and intuitive alternative to a tagging system, thanks.
Maybe you could add this snippet of code to the docs (if it's not already there), I know it's just pure and simple Swift code, but maybe it could point developers coming from other DI frameworks that offer a tagging system in the right direction. Thanks again.
from factory.
https://hmlongco.github.io/Factory/documentation/factory/tags/
from factory.
Thanks for taking that into consideration.
I've updated the forked repository following your suggestion, the previous poc also leads to an unattended behavior if you tag the factory in its computed variable.
from factory.
I have the code for later consideration should I decide to implement this as a feature in Factory, but for now I think I'll go with the documentation suggestion and see if that covers most of the bases for most of the people.
Thanks for the suggestions.
from factory.
Related Issues (20)
- @InjectedLazyObject HOT 1
- Multiple previews and resolving different values for a singleton HOT 1
- 2.3 no longer works on linux - missing os_unfair_lock HOT 3
- Some minor suggestions and issues. HOT 6
- UnitTesting Cached Service Issue/Question HOT 3
- Resetting instance variables on long lived object when resetting scope HOT 5
- very heavy load on the CPU HOT 9
- Cannot build XCFramework HOT 1
- Missing Registeration in Multi Module HOT 1
- Name spacing conflict HOT 4
- Are you interested for macro ? HOT 2
- Can not build app for deivce ios 15 when import Factory HOT 5
- complete Swift Concurrency Checking: "Reference to class property 'shared' is not concurrency-safe because it involves shared mutable state" HOT 1
- Using Factory in a Sendable conforming Class HOT 1
- UITests LaunchArguments Failing in Headless Mode HOT 1
- What is diffrence between this framework and singleton pattern? HOT 1
- Building xcframework on Xcode 15.0 HOT 13
- Support @Bindable with @Injected property wrappers HOT 3
- is it possible to inject swiftui view through factory? HOT 1
- Privacy manifest file HOT 3
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.