Using this library with Vapor. Possible? #186
Unanswered
nashysolutions
asked this question in
Q&A
Replies: 1 comment
-
@nashysolutions Hi! I use Dependencies + Vapor and find it very convenient. It's important to be careful: dependencies can escape sometimes and it leads to weird and hard debuggable bugs. To avoid escaping I use this middleware: import Dependencies
import Foundation
import Vapor
public struct DependencyMiddleware: AsyncMiddleware {
private let values: DependencyValues.Continuation
public init() {
values = withEscapedDependencies { $0 }
}
public func respond(to request: Request, chainingTo next: AsyncResponder) async throws -> Response {
try await values.yield {
try await withDependencies {
$0.logger = request.logger
} operation: {
try await next.respond(to: request)
}
}
}
} Also I had to wrap websocket methods with |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
It seems my Vapor App target and Vapor Test target are both running and setting independent instances of 'DependencyValues'. The docs mention preventing an iOS App from executing code using the dynamic overlay library, which I may have to do with Vapor. This would however, prevent end to end testing, but won't be the end of the world.
Has anyone else had any success with Vapor + this library before?
Beta Was this translation helpful? Give feedback.
All reactions