Inject to an array?

Hi,

this might be a simple question, however i didn’t found sth. about it in the topics, so:

My class looks like this

import { Module } from '../modules/abstract/module.abstract';
import { SomeModule1 } from '../modules/someModule1/someModule1.module';
import { SomeModule2 } from '../modules/someModule2/someModule2.module';

...

constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, public events: Events, private someModule1: SomeModule1, private someModule2: SomeModule2) {...} 

...

this works like a charm.

Nevertheless it’d like to use it this way:

constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, public events: Events, private moduleArray: [someModule1: SomeModule1, someModule2: SomeModule2,]) {...} 

but this gave me this error:

StaticInjectorError(AppModule)[MyApp -> Array]: StaticInjectorError(Platform: core)[MyApp -> Array]: NullInjectorError: No provider for Array!

is it possible to achieve what i want, without filling an array up in the constructor nor defining a class like ‘ModuleContainer’ which just preservs my modules? Do i have to play for this with this injector-thing?

No, not directly, because the injection magic relies on the type of each parameter to know what to do. You could make an injection factory as described in here, but at the end of the day I would suspect that you will look at the result and say “this is pretty opaque and hard to maintain”. I think you would be better off in the long run making all the dependencies explicit, if for no other reason than readability.

Hm ok, seems you are right. Well - thanks anyway. When I think it over, readability and maintenance was, what i was aiming for.