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 {}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With