满分-分数
说明
依赖性注射容器, PSR-11 (中文(简体) ) 启发.
所需资源
- 节点: 22
- bby/bby-dic-型: ^ 2.4.0 (中文(简体) )
安装
穿过 国家预防机制 作为 {\fn黑体\fs22\bord1\shad0\3ahbe\4ah00\fscx67\fscy66\2chffffff\3ch808080}我需要你来帮忙。 。 。 .
npm i @chubbyts/chubbyts-dic@^2.4.1
使用量
设定
import { Container } from '@chubbyts/chubbyts-dic-types/container';
import { createContainer } from '@chubbyts/chubbyts-dic/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<Logger>('logger'));
}]
]));
设定
import { Container } from '@chubbyts/chubbyts-dic-types/container';
import { createContainer, createParameter, Factory } from '@chubbyts/chubbyts-dic/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<Logger>('logger'));
});
// existing (replace)
container.set('myService', (container: Container): MyService => {
return createMyService(container.get<Logger>('logger'));
});
// existing (extend)
container.set('myService', (container: Container, existingFactory?: Factory): MyService => {
if (!existingFactory) {
throw 'Missing service';
}
return decorateMyService(existingFactory(container), container.get<Cache>('cache'));
});
// parameter
container.set('param', createParameter('value'));
获取
import { createContainer } from '@chubbyts/chubbyts-dic/container';
import { MyService } from './service/my-service';
const container = createContainer();
container.get<MyService>('myService');
有过
import { createContainer } from '@chubbyts/chubbyts-dic/container';
const container = createContainer();
container.has('myService');
版权
2026 道米尼克·佐格(英语: