You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
so that token mappings are co-located with their relevant service implementations. But, there could be an issue if I introduce circular dependencies... for example:
// ./name.service.tsimport{injected,token}from'brandi';import{Logger}from'./logger.service';classNameService{statictoken=token<NameService>('NameService');constructor(privatereadonlylog: Logger){}asyncgetName(){this.log.debug('called NameService.getName()');return'Sally';}}injected(NameService,Logger.token);// ./logger.service.tsimport{injected,token}from'brandi';import{NameService}from'./name.service';classLogger{statictoken=token<Logger>('Logger');constructor(privatereadonlynameSvc: NameService){}asyncsayHello(){constname=awaitthis.nameSvc.getName();console.log(`Hello, my name is ${name}!`);}debug(message: string){console.log('[debug]',message);}}injected(Logger,NameService.token);
I think this could be resolved by allowing tokens to be provided as functions, like:
It’s clear what the problem is but it seems that the problem can be solved in a different way. You can move the token to a separate file like tokens.ts or MyService.token.ts.
Brandi is also design to be used on the frontend, and the way you suggested provokes extra code entering the bundle when you import MyService for the token, but do not actually use the class implementation.
I'm interested in using a pattern like this for injected services:
so that token mappings are co-located with their relevant service implementations. But, there could be an issue if I introduce circular dependencies... for example:
I think this could be resolved by allowing tokens to be provided as functions, like:
Then the token could be fully resolved when
container.get()
is called.The text was updated successfully, but these errors were encountered: