Is it possible to use two singletons and enable them to call each other in the following manner?
import 'reflect-metadata';
import { Container, inject, injectable } from 'inversify';
let container = new Container();
@injectable()
class Dom {
private domUi: DomUi;
constructor (domUi: DomUi) {
this.domUi = domUi;
}
}
@injectable()
class DomUi {
private dom: Dom;
constructor (dom: Dom) {
this.dom = dom;
}
}
@injectable()
class Test {
constructor (dom: Dom) {
console.log(dom);
}
}
container.bind<Dom>(Dom).toSelf().inSingletonScope();
container.bind<DomUi>(DomUi).toSelf().inSingletonScope();
const test = container.resolve(Test);
Encountering this error message:
Error: Missing required @inject or @multiInject annotation in: argument 0 in class Dom.
How can this issue be resolved? Even after trying out @inject
and @multiInject
, the problem persists.
Could there be a more suitable approach to tackle this conundrum from a design pattern perspective?