Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Multi Provider dependency order

Does the Angular DI Multi Provider mechanism guarantee some sort of order?

Example:

const TOKEN: OpaqueToken = new OpaqueToken('token');

@Injectable() 
class MyService (@Inject(TOKEN) deps: any[]) {/* What is order of deps? */}

@NgModule ({
  providers: [ 
    {provide: TOKEN, multi: true, useValue: 1},
    {provide: TOKEN, multi: true, useValue: 2},
    {provide: TOKEN, multi: true, useValue: 3},
    MyService
})
class MyModule {}
like image 216
Krzysztof Bogdan Avatar asked Dec 20 '25 09:12

Krzysztof Bogdan


1 Answers

I would say yes. Although I cannot find the documentation to say definitively. However, from personal experience, I can say that they're always provided in the same order. We use multiple HttpInterceptors as well as some injectable actions throughout our applications and they're always injected in the order they're provided. Also, since APP_INITIALIZER and HTTP_INTERCEPTOR are provided this way I would assume that it's true even more so. You wouldn't want your HTTP_INTERCEPTOR's being provided in random order.

like image 54
AlmaniaM Avatar answered Dec 22 '25 00:12

AlmaniaM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!