Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

A simple library that provides a basic service layer for Hummingbird on top of app extensions.

Notifications You must be signed in to change notification settings

BinaryBirds/hummingbird-services

Repository files navigation

HummingbirdServices

A simple library that provides a basic service layer for Hummingbird on top of app extensions.

Install

Add the repository as a dependency:

.package(url: "https://github.com/binarybirds/hummingbird-services", from: "1.0.0"),

Add HummingbirdServices to the target dependencies:

.product(name: "HummingbirdServices", package: "hummingbird-services"),

Update the packages and you are ready.

Usage example

import Hummingbird
import HummingbirdServices

/// test service
final class TestService {
    var status = "ready"
}

/// test service extension
extension HBApplication.Services {
    
    var test: TestService {
        get {
            get(\.services.test)
        }
        nonmutating set {
            set(\.services.test, newValue) { _ in }
        }
    }
}

/// app shortcut for the test service
public extension HBApplication {

    /// test service reference
    var test: TestService {
        services.test
    }
}

/// req shortcut for the test service
public extension HBRequest {

    /// test service reference
    var test: TestService {
        application.services.tests
    }
}

/// initiate the service
app.services.test = TestService()

/// use the test service
print(app.test.status)
print(req.test.status)

About

A simple library that provides a basic service layer for Hummingbird on top of app extensions.

Resources

Stars

Watchers

Forks

Languages