I'm trying to implement a cascading with tsyringe.
I have a singleton database class that has to be injected in a service class that have to be injected in a controller class:
@injectable()
class DashboardDAO implements IDashboardDAO {...}
@injectable()
class DashboardService implements IDashboardService {
construtor(@inject('DashboardDAO') private dashboardDao: IDashboardDAO){}
}
@injectable()
class DashboardController {
construtor(@inject('DashboardService') private dashboardService: IDashboardService){}
}
in my container i have the following configuration.
/** REPOSITORIES */
container.registerSingleton<IDashboardDAO>('DashboardDAO', DashboardDAO);
/** SERVICES */
container.registerSingleton<IDashboardService>('DashboardService', DashboardService);
I whould like to instantiate the controller with everything injected, something like this:
const controller = container.resolve(DashboardController);
It couldn't resolve... I'm getting the following error:
Attempted to resolve unregistered dependency token
If I do the code below works fine, but i would like to resolve the controller with all injections.
container.resolve(DashboardService);
Anyone knows why?
Tks!