Variable binding (Injection)

Last updated 14 days ago
  • @Inject(MyService) private myService:MyService

  • @Inject("MyService") private myService:MyService

  • constructor(private myService:MyService)

    ‚Äč

Retrieve value from the "container"

The InversifyJS container is handling and storing singleton objects. The container is stored on the server instance, each request and the ServerContainerService

Retrieve the container object

Check the previous section (Dynamic injectables)

Retrieve service instance

After retrieving the container we able to get the service instance as following:

  • private myService:MyService = container.get(MyService)

Or

  • private myService:MyService = container.get("MyService")