https://github.com/bemit/service-service
NodeJS service and configuration container with strong typings.
https://github.com/bemit/service-service
Last synced: 24 days ago
JSON representation
NodeJS service and configuration container with strong typings.
- Host: GitHub
- URL: https://github.com/bemit/service-service
- Owner: bemit
- License: mit
- Created: 2022-07-27T10:33:58.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-26T20:08:16.000Z (over 2 years ago)
- Last Synced: 2024-04-25T12:01:48.521Z (about 1 year ago)
- Language: TypeScript
- Size: 325 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ServiceService
[](https://www.npmjs.com/package/service-service)
[](https://github.com/bemit/service-service/actions)
[](https://github.com/bemit/service-service/blob/main/LICENSE)
[](https://codecov.io/gh/bemit/service-service/branch/main)
Dead simple service and config container, with lazy initialization and strong typings.
```typescript
import { ServiceContainer } from 'service-service'class ExampleService {
private readonly name: stringconstructor(name: string, options: { a: string }) {
this.name = name
}getName() {
return this.name
}
}export interface AppConfig {
name: string
}export const container = new ServiceContainer()
// 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](https://github.com/bemit/service-service/blob/main/LICENSE)
© 2022 [bemit](https://bemit.codes)