Reputation: 11065
I want to do something like this:
{
provide: [Token1, Token2],
useClass: MyService,
},
Something which I would do with Autofac in .Net like containerBuilder.Register<MyService>().As<IService1>().As<IService2>()
. The instance of the object requested via both tokens should be the same. Is it possible with angular?
Upvotes: 5
Views: 1292
Reputation: 106
Try this one.
{ provide: Token1, useClass: MyService} { provide: Token2, useExisting: MyService}
https://angular.io/guide/dependency-injection-providers
Upvotes: 8
Reputation: 1164
To provide the same instance you can use useExisting
[
{ provide: Token1, useClass: MyService},
{ provide: Token2, useExisting: MyService}
]
https://angular.io/api/core/ExistingProvider
Upvotes: 3