Dependency injection container (DIC), PSR-11 inspired.
npm install @chubbyts/chubbyts-dic














Dependency injection container (DIC), [PSR-11][2] inspired.
* node: 18
* [chubbyts/chubbyts-dic-types][3]: ^2.0.0
Through NPM as [@chubbyts/chubbyts-dic][1].
``ts`
npm i @chubbyts/chubbyts-dic@^2.0.2
`ts
import { Container } from '@chubbyts/chubbyts-dic-types/dist/container';
import { createContainer } from '@chubbyts/chubbyts-dic/dist/container';
import { Logger } from 'some-logger/dist/logger';
import { createMyService, decorateMyService, MyService } from './service/my-service';
const container = createContainer();
container.sets(new Map([
['myService', (container: Container): MyService => {
return createMyService(container.get
}]
]));
`
`ts
import { Container } from '@chubbyts/chubbyts-dic-types/dist/container';
import { createContainer, createParameter, Factory } from '@chubbyts/chubbyts-dic/dist/container';
import { Cache } from 'some-cache/dist/cache';
import { Logger } from 'some-logger/dist/logger';
import { createMyService, MyService } from './service/my-service';
const container = createContainer();
// new
container.set('myService', (container: Container): MyService => {
return createMyService(container.get
});
// existing (replace)
container.set('myService', (container: Container): MyService => {
return createMyService(container.get
});
// existing (extend)
container.set('myService', (container: Container, existingFactory?: Factory): MyService => {
if (!existingFactory) {
throw 'Missing service';
}
return decorateMyService(existingFactory(container), container.get
});
// parameter
container.set('param', createParameter('value'));
`
`ts
import { createContainer } from '@chubbyts/chubbyts-dic/dist/container';
import { MyService } from './service/my-service';
const container = createContainer();
container.get
`
`ts
import { createContainer } from '@chubbyts/chubbyts-dic/dist/container';
const container = createContainer();
container.has('myService');
``
2025 Dominik Zogg
[1]: https://www.npmjs.com/package/@chubbyts/chubbyts-dic
[2]: https://www.php-fig.org/psr/psr-11
[3]: https://www.npmjs.com/package/@chubbyts/chubbyts-dic-types