I'm new to using InversifyJS and I see a lot of basic examples of a class with a constructor using @inject for dependencies. Like this...
export class Service {
protected depA: DependencyA;
protected depB: DependencyB;
constructor(
@inject(DependencyA) dependencyA: DependencyA,
@inject(DependencyB) dependencyB: DependencyB
) {
this.depA = dependencyA;
this.depB = dependencyB;
}
}
Where those injected dependencies have 0 further dependencies.
However, I have coworkers that don't use that and instead use something like...
private readonly service = container.get<Interface>(TYPES.InterfaceSymbol);
to call any necessary dependency service.
I'd like to better understand when to use one over the other with this kind of sample case. Writing it out as nested lists where the further indented list item is its dependency.
- RootService
- BusinessLogicAService
- RepoAService
- GeneralDbConnectionService
- RepoAService
- BusinessLogicBService
- RepoBService
- GeneralDbConnectionService
- RepoBService
- BusinessLogicAService
Plus a LoggerService that replaces console.log() and should be injectable into any service.
In this case, when should I use the constructor with @inject params vs the container.get() (or some other means you know that I don't)?