             ]
         }, as: .test)
         
-        app.middleware.use(PostRepositoryMiddleware {
+        app.posts.use {
             DatabasePostRepository(database: $0.db(.test))
-        })
+        }
         
         app.get("foo") { req -> EventLoopFuture<[Post]> in
             req.posts.all()

protocol PostRepository {
    func all() -> EventLoopFuture<[Post]>
}

struct PostRepositoryMiddleware: Middleware {
    let makePosts: (Request) -> PostRepository
    
    func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response> {
        request.posts = self.makePosts(request)
        return next.respond(to: request)
    }
}

extension Request {
    var posts: PostRepository {
        get {
            guard let post = self.userInfo["post"] as? PostRepository else {
                fatalError("PostRepository not configured on request")
            }
            return post
        }
        set {
            self.userInfo["post"] = newValue
        }
    }
}

    func testRepositoryPatternStatic() throws {
        let app = Application(.testing)
        defer { app.shutdown() }

        var posts: [Post] = [
            .init(content: "a"),
            .init(content: "b")
        ]

        app.posts.use {
            TestPostRepository(posts: posts, eventLoop: $0.eventLoop)
        }

        app.get("foo") { req -> EventLoopFuture<[Post]> in
            req.posts.all()
        }

        try app.testable().test(.GET, "foo") { res in
            XCTAssertEqual(res.status, .ok)
            XCTAssertEqualJSON(res.body.string, posts)
        }

        posts.append(.init(content: "c"))

        try app.testable().test(.GET, "foo") { res in
            XCTAssertEqual(res.status, .ok)
            XCTAssertEqualJSON(res.body.string, posts)
