Skip to content

NodeJS service and configuration container with strong typings.

License

Notifications You must be signed in to change notification settings

bemit/service-service

Repository files navigation

ServiceService

npm (scoped) Github actions Build MIT license Coverage Status Typed

Dead simple service and config container, with lazy initialization and strong typings.

import { ServiceContainer } from 'service-service'

class ExampleService {
    private readonly name: string

    constructor(name: string, options: { a: string }) {
        this.name = name
    }

    getName() {
        return this.name
    }
}

export interface AppConfig {
    name: string
}

export const container = new ServiceContainer<AppConfig>()

// specify configuration values:
container.configure('name', 'Example App')
// get configuration values:
container.config('name')

// define services, pass `constructor` params as array:
container.define(ExampleService, [
    'the-name',
    {
        a: 'a-value',
    },
])

// provide params as function, for lazy execution (on first `use`)
container.define(ExampleService, () => [
    'the-name',
    {
        a: 'a-value',
    },
])

// use the service:
const service = container.use(ExampleService)
service.getName() // will return `the-name`

ESM only package

License

MIT License

© 2022 bemit

About

NodeJS service and configuration container with strong typings.

Resources

License

Stars

Watchers

Forks

Packages

No packages published