本文整理汇总了TypeScript中@lib/dependency-injection/Container.Container.resolve方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Container.resolve方法的具体用法?TypeScript Container.resolve怎么用?TypeScript Container.resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@lib/dependency-injection/Container.Container
的用法示例。
在下文中一共展示了Container.resolve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('resolve a dependency that has no other dependencies', (): void => {
const container: DIContainer = new DIContainer();
container.register<number>(
'a',
() => {
return 12;
}
);
container.register<number>(
'b',
() => {
return 45;
}
);
container.register<number>(
'add',
// tslint:disable-next-line typedef
(a, b) => {
return a + b;
}
);
expect(container.resolve('add')).toEqual(57);
});
示例2: it
it('resolve value from di container', (): void => {
const di: DIContainer = factory();
di.register<number>(
'a',
() => {
return 16;
}
);
@inject
class Adder {
private readonly _a: number;
constructor(a: number) {
this._a = a;
}
public add(b: number): number {
return this._a + b;
}
}
const adder: Adder = di.resolve<Adder>('Adder');
expect(adder.add(3)).toBe(19);
});