小编Art*_*Dev的帖子

InversifyJS 绑定装饰器和惰性注入

我将 InversifyJS 与绑定和惰性注入装饰器一起使用,并且收到下一个错误:

找不到 serviceIdentifier: Symbol(ClassB) 的匹配绑定

这是代码:

inversify.config.ts

import { Container } from 'inversify';
import getDecorators from 'inversify-inject-decorators';
import { buildProviderModule, provide } from 'inversify-binding-decorators';
import Types from './types';

const container = new Container();

container.bind<MyType>(Types.MyType)
    .to(MyType);

const { lazyInject } = getDecorators(container, false);

container.load(buildProviderModule());

export { container, lazyInject, provide };
Run Code Online (Sandbox Code Playgroud)

MyType.ts

import { inject, injectable } from 'inversify';

@injectable()
export class MyType{
    constructor(
        @inject(Q) private readonly Q: Q,
        @inject(W) private readonly W: W,
        @inject(E) private readonly E: E) { …
Run Code Online (Sandbox Code Playgroud)

typescript javascript-import inversifyjs javascript-decorators

5
推荐指数
0
解决办法
3526
查看次数