service-service

Dead simple container for service definition and lazy initialization.

Usage no npm install needed!

<script type="module">
  import serviceService from 'https://cdn.skypack.dev/service-service';
</script>

README

ServiceService

Dead simple container for service definition and lazy initialization - with strong typings.

import { ServiceService } from 'service-service'

class ExampleService {
    private readonly name: string

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

    getName() {
        return this.name
    }
}

// define it in the app's bootstrap file:
ServiceService.define(ExampleService, ['the-name', {
    a: 'a-value',
}])

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

License

License: MIT

© 2022 Michael Becker