Vapor v4.0.0-beta.2 Release Notes

Release Date: 2019-12-09 // over 4 years ago
    • ๐Ÿ”จ Services has been refactored to be more type-safe. (#2098)

    Services, Container, and Provider have been replaced by a pattern built on Swift extensions. This is best explained with examples.

    Telling Vapor to use Leaf:

    import Leafimport Vapor// beta.1s.register(ViewRenderer.self) { c inreturn c.make(LeafRenderer.self) }// beta.2app.views.use(.leaf)
    

    Registering a factory service:

    // beta.1s.register(Foo.self) { c inreturn Foo(...) } app.make(Foo.self).bar()// beta.2extension Application { var foo: Foo { return Foo(...) } } app.foo.bar()
    

    Registering a singleton service:

    // beta.1s.register(Foo.self) { c inreturn Foo(...) } app.make(Foo.self).bar = 0app.make(Foo.self).bar += 1print(app.make(Foo.self).bar) // 1// beta.2extension Application { var foo: Foo { if let existing = self.storage[FooKey.self] as? Foo { return existing } else { let new = Foo() self.storage[FooKey.self] = new return new } } private struct FooKey: StorageKey { typealias Value = Foo } } app.foo.bar = 0app.foo.bar += 1print(app.foo.bar) // 1
    

    This new pattern of extending Application also works with Request:

    extension Application { var foo: Foo { ... } }extension Request { var bar: Bar { return self.application.foo.bar(for: self) } }
    

    ๐Ÿ”จ Validations has been refactored to yield better and more type-safe errors (#2071)

    Authentication methods are now grouped under a new req.auth helper (#2111)

    All authenticators now accept Request in their authenticate methods (#2111)

    โž• Added new ErrorSource struct to the AbortError protocol (#2093)

    ๐Ÿ”Š This new struct makes it easier to pass around information about where an error came from. It also makes it easier to indicate that a given error has no source information. This helps the logger avoid muddying logs with useless error source information.

    ๐Ÿ‘ RouteBuilder HTTP method helpers now support an array of [PathComponent] (#2097)

    โœ… User-provided HTTP headers are no longer ignored when using XCTVapor test methods (#2108)

    ๐Ÿง Enabled test discovery on Linux (#2118)