Today I stumbled upon something that I didn\'t think would cause me trouble.
In Java and Spring, I can declare two beans that both implement a given interface, while
In order for a provider to be injected, it should be registered as a provider. There's no IConfigurationService
provider. And it cannot be a provider, because interfaces don't exist in compiled JS code.
The common practice for interfaces that are supposed to be used as provider tokens is to be abstract classes:
abstract class ConfigurationService { ... }
@Injectable()
class WebAppConfigurationService extends ConfigurationService { ... }
...
providers: [{ provide: ConfigurationService, useClass: WebAppConfigurationService }]
...
This recipe is commonly used by Angular 2 itself, e.g. abstract NgLocalization class and concrete NgLocaleLocalization implementation.