Vapor: 4.108.0 Release

Release date:
December 16, 2024
Previous version:
Could not determine previous release version
Magnitude:
0 Diff Delta
Contributors:
0 total committers
Data confidence:
Commits:

Top Contributors in 4.108.0

Could not determine top contributors for this release.

Directory Browser for 4.108.0

We couldn't find a release before this one

Release Notes Published

What's Changed

Make Services in Vapor Usable by @0xTim in #2901

This adds real support to Vapor to make it easy to integrate different services that can be tested.

For example, if you have a service defined as:

protocol MyService {
    func `for`(_ request: Request) -> MyService
    func doSomething() -> String
}

You may then have a real implementation:

import Vapor

struct MyRealService: MyService {
    let logger: Logger
    let eventLoop: EventLoop

    func `for`(_ request: Vapor.Request) -> MyService {
        return MyRealService(logger: request.logger, eventLoop: request.eventLoop)
    }

    func doSomething() -> String {
        return "Tada"
    }

}

This is a very contrived example, but shows a service that needs a Logger and EventLoop - things that are normally tied to specific requests. Doing this in a safe and testable way involves a lot of boilerplate. This moves the boilerplate into Vapor to make it easier to do.

extension Application.Services {
    var myService: Application.Service<MyService> {
        .init(app…

…

Reviewers

Thanks to the reviewers for their help: - @Joannis - @dimitribouniol - @Andrewangeta

This patch was released by @0xTim

Full Changelog: https://github.com/vapor/vapor/compare/4.107.0...4.108.0