createInjectionToken()
function createInjectionToken\<T\>(description: string): InjectionToken\<T\>;
Defined in: src/lib/di/index.ts:344
Create an injection token for an interface. Use this when you want to inject an interface rather than a concrete class.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
description | string | A description for the token (used in error messages). |
Returns
A symbol that can be used as an injection token.
Example
// Define the token
export const ICharacterService = createInjectionToken\<ICharacterService\>("ICharacterService");
// Register the implementation
registerService(ICharacterService, new CharacterServiceImpl(), "characters");
// Inject the interface
class MyService {
private characterService = inject(ICharacterService);
}