https://github.com/bemit/service-service
NodeJS service and configuration container with strong typings.
https://github.com/bemit/service-service
Last synced: 8 months 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 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-26T20:08:16.000Z (almost 4 years ago)
- Last Synced: 2025-09-13T23:59:36.518Z (9 months 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: string
constructor(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)