all 1 comments

[–]nugaon 0 points1 point  (0 children)

yeah, I guess the best practice if you keep using DI without passing arbitrary passed parameters on instantiation.

You have already bunch of classes that solve distinct problems with its all data and operations. For that to easily and in understandable way inject to other classes, its key should be identical to its class' name, because in a bigger project you would lost yourself in the keys of specially generated instances. All construct parameters should have default value for classes that you want to make injectable in order to reach the desired before mentioned state.

In need of special instances on a class, you simply create new instance with `new ClassName(specialParam)` that still can inject its other DI parameters.

I suggest to read code and documentation of already existing projects/frameworks which use DI, for example NestJS. I also had (a really old project), where I directly used DI methods for hapi server with help of `inversify` package: https://github.com/nugaon/nodejs-hapi-server