本文整理匯總了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);
});