Inversify JS переплетные декораторы и ленивый инжект - PullRequest
0 голосов
/ 02 мая 2020

Я использую Inversify JS с декораторами привязки и отложенного ввода, и я получаю следующую ошибку:

Не найдено подходящих привязок для 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 };

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) {
    }
}

Main.ts

import 'reflect-metadata';

import './class-a';
import './class-b';

import { MyType } from './my-type';
import Types from './di/types';
import { container } from './di/inversify.config';


const main = async () => {
    const mytype = container.get<MyType>(Types.MyType);
    await mytype.execute();
};

main()
    .then(() => {
        console.info('Started application...');
    })
    .catch((error) => {
        console.error(error);
    });

ClassA.ts

import { inject } from 'inversify';
import Types from '../../di/types';
import { provide } from '../../di/inversify.config';
import { ClassB } from '../../some/directory/class-b';

@provide(Types.ClassA)
export class ClassA implements IClassA {
    constructor(
        @inject(ClassX) private readonly ClassX: ClassX,
        @inject(ClassY) private readonly ClassY: ClassY) {
    }

    @lazyInject(ClassB)
    private readonly ClassB!: ClassB;
}
export default ClassA;

ClassB.ts

import Types from '../../di/types';
import { provide } from '../../di/inversify.config';

@provide(Types.ClassB)
export class ClassB implements IClassB{
...
}
export default ClassB;

types.ts

const Types = {
    ClassA: Symbol.for('ClassA'),
    ClassB: Symbol.for('ClassB'),
};

export default Types;

Я попытался ответить на этот вопрос Связывание классов с введением свойства в ядро in insify но все равно безуспешно

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...