// myType.ts
export interface IMyInjectableType {}
@injectable()
export class MyInjectableType implements IMyInjectableType {}
// myTypeInjects.ts
export const IMyInjectableType$ = createInjectToken<IMyInjectableType>('IMyInjectableType');
// registrator.ts
export const MyRegistrator: ExtensionRegistrator = {
async registerTypes(container) {
container.bind(IMyInjectableType$).to(MyInjectableType);
}
};
@extension()
export class MyCardUIExtension extends CardUIExtension {
constructor(
@inject(IMyInjectableType$) private readonly _myType: IMyInjectableType
) {
super();
}
// ...
}
For example, change the default HttpClient
dependency of the card service:
// myApiClient.ts
@injectable()
export class MyApiClient extends ApiClient {
protected override async getDefaultOptions(): Promise<ApiClientOptions> {
const options = await super.getDefaultOptions();
options.timeout = 5000; // change default timeout
return options;
}
}
// registrator.ts
export const MyRegistrator: ExtensionRegistrator = {
async registerTypes(container) {
container.bind(IApiClient$).to(MyApiClient).whenInjectedInto(ICardService$);
}
};
@extension()
export class MyCardUIExtension extends CardUIExtension {
constructor(
@inject(IMyInjectableType$, { optional: true })
private readonly _myType: IMyInjectableType | null
) {
super();
}
// ...
}
Generated using TypeDoc