Comments (2)
You do have a knack, don't you? In all the years I've done this I've not had a single request for some way to handle a throwing initializer.
Regardless, if it throws then you're not going to have much of choice. That factory closure has to return something. You have two options. The first, as mentioned, is making it optional and nil.
The second depends on the type of object being returned. You could, perhaps, do...
public extension Container {
var service: Factory<MyProtocol> {
self {
do (
return try MyService()
} catch {
// log error
return StubMyProtocol()
}
}
.singleton
}
}
If the library could fail, but is some sort of logging or analytics library, then return a mock for the rest of the world to interact with. If it's an API, then just have the mock error out when accessed.
from factory.
Yeah. It's a tricky one. I have a service which is loading a bunch of data from JSON files on startup, so the problem I was addressing was what happens if something in that data is off. I've since worked around it, but it's an interesting question.
from factory.
Related Issues (20)
- is it possible to inject swiftui view through factory? HOT 1
- Privacy manifest file HOT 3
- Issues with SPM packages and Container static shared instance HOT 2
- Question: How do I achieve scene scoped dependencies HOT 10
- Parameter factory cache does not take parameters into account HOT 2
- Xcode compile error in `FactoryKey.init(type:key:)` due to use of @inlinable HOT 3
- Release for Privacy manifest and iOS 15 HOT 4
- Sendable conformance for `Container` HOT 5
- Replace resolver with the factory pacakge but my app architure is modular HOT 5
- UITesting Question - Mock Response Scaling Concern HOT 2
- typealias with 2 protocols leads to EXC_BAD_ACCESS HOT 1
- SwiftUI previews with multiple modules HOT 2
- Is there a way to reset all containers in tests HOT 3
- Typo on Scopes.swift documentation HOT 1
- Cannot form key path to main actor-isolated property; this is an error in Swift 6 HOT 6
- Async Init Support for Actors? HOT 3
- Unable to override a context-based factory HOT 3
- Using Factory between different targets in a package and app HOT 3
- modular approach and scopes HOT 2
- Swift 6 concurrency warnings HOT 6
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.