5

I'm looking for a way to get the list of all injected/injectable services on a component or at application level.

Currently Injector only provide a get method that require an argument, I'm looking for something like a getAll method.

I need to do some introspection on those services that's why I need this feature.

Could you please tell me if there's any way to achieve this currently?

Update

Here's my need.

I have a abstract class A which contains a method isEveryThingOk (just an example).

This class is inherited in 30+ services.

Now let's say I have 5,10 or 20 applications which are using several of those services, but never all of them.

In each of these applications I would like to check if everything is OK for all loaded services that extends my class A.

Currently I need to create an array of all of the used services in each of my applications and go through this array to run my test.

It's very trouble some and error prone to manage those arrays manually. The services might be loaded indirectly through modules.

So in my main application component I would like to loop through all loaded services, test if they match class A, and if they do, run my test on each of them.

This way I'm sure to never miss any of them and also not to go through an unloaded service. This also allow me save a lot of time, energy and prevent error of maintaining those list manually.

Of course I don't want to create a component that will contain all the services because this would include them in the bundle of each application even if they are not used.

Christophe
  • 51
  • 4
  • As far as I'm aware the injector doesn't expose this. Could you give some context; *what* "introspection"? – jonrsharpe Mar 11 '19 at 08:16
  • I have updated my description – Christophe Mar 12 '19 at 09:39
  • Have you considered the `multi` provider, see e.g. https://stackoverflow.com/q/36205892/3001761 – jonrsharpe Mar 12 '19 at 09:49
  • According to my understanding, `multi` only works if I inject all the services under the same class name (in this case `A`). This means I won't be able to access the services using their own class name anymore which would be very painful to refactor and use everywhere else. – Christophe Mar 13 '19 at 11:44

0 Answers0