import DatabaseClientLive import Dependencies import Vapor struct DependenciesMiddleware: AsyncMiddleware { private let values: DependencyValues.Continuation init() { self.values = withEscapedDependencies { $0 } } func respond(to request: Request, chainingTo next: any AsyncResponder) async throws -> Response { try await values.yield { try await withDependencies { $0.database = .live(database: request.db) } operation: { try await next.respond(to: request) } } } }