It’s pretty frequent to see in addons an initializer that does a bunch of injections such as:
application.inject('route', serviceName, serviceLookupName);.
I understand it’s easy and works well, but it seems to me that it makes the application less readable. I’d like to read from you about whether this is a good practice and what could be the reasons to prefer automatic injection over a manual injection at class-level.
From my perspective, there are a number of downsides:
- This is too broad: If I want to inject something in all the objects of type X, why wouldn’t I extend the initial type and use that instead?
- looking at a class (let’s say a Component), I have to know and remember beforehand that it is not “only” an Ember Component but a “component with X and Y already injected”. I don’t like implicit behaviour
- I can’t easily say where the injection is used. When you manually do the injection on specific classes, it makes it much easier to understand the impact of your injection in your app.
Do you agree or disagree? Do you inject dependencies in your classes from the initialisers? Is there a recommended practice at all?
Bye, thanks for reading