Dynamic injectables
Registration can be done in run time using the container 'bind' method.The bind method allows to bind a class\function\value to a property.
Retrieve the container object
We are able to retrieve the singleton class instance using the following methods:
<HttpServer>server.container
req.container
ServerContainerService.getContainerById(serverInstanceId)
- Using the HttpServer object instanceId.
Example
server.container.bind('HttpHandler').to(Http);
server.container.bind('DBConfig').toConstant({ip: 10.10.10.10});
server.container.bind('Human').toFactory(()=>new Human());
Last updated