0.1.3 • Published 2 years ago

service-service v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

0.1.3

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.0.3

2 years ago

0.1.1

2 years ago

0.0.4

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago