0

我想在创建后使用 inversify 的 @injectable 装饰器更新一个类;用例是我想使用像 ts-auto-mock 这样的模拟库为我创建一个模拟,然后应用 @injectable 装饰器,这样我就可以将模拟绑定到服务类型。

const mockExampleService = createMock<ExampleService>();
// I want to apply the @injectable decorator to mockExampleService here

// inversify.unit-config.ts
const container = new Container();
const.bind<ExampleService>(TYPES.ExampleService).to(mockExampleService);

4

1 回答 1

1

当然!Inversify正是为此目的提供了一个装饰功能。

const mockExampleService = createMock<ExampleService>();
decorate(injectable(), mockExampleService);

// inversify.unit-config.ts
const container = new Container();
const.bind<ExampleService>(TYPES.ExampleService).to(mockExampleService);
于 2020-03-06T19:52:45.297 回答