0

I want to create little CQRS framework for my Typescript Node.js project.

I wish to resolve class by it's name from inversify.js container. I need something like that:

let x = container.get("Foo");

where Foo is regular class and container is Container object from inversify.js.

Is it possible to do what I want?

tBlabs
  • 2,619
  • 3
  • 18
  • 22

1 Answers1

0

You should be able to do the following:

import { Container, injectable } from "inversify";

@injectable()
class Foo {
    // ...
}

const container = new Container();
container.bind(Foo).toSelf();

const foo = container.get(Foo);

Or (if foo is the composition root):

import { Container, injectable } from "inversify";

@injectable()
class Foo {
    // ...
}

const container = new Container();
const foo = container.resolve(Foo);
Remo H. Jansen
  • 23,172
  • 11
  • 70
  • 93