Module Application.DI

example
  1. create injectable type:
// myType.ts
export interface IMyInjectableType {}

@injectable()
export class MyInjectableType implements IMyInjectableType {}

// myTypeInjects.ts
export const IMyInjectableType$ = createInjectToken<IMyInjectableType>('IMyInjectableType');
  1. register type
// registrator.ts
export const MyRegistrator: ExtensionRegistrator = {
async registerTypes(container) {
container.bind(IMyInjectableType$).to(MyInjectableType);
}
};
example
@extension()
export class MyCardUIExtension extends CardUIExtension {
constructor(@inject(IMyInjectableType$) private readonly _myType: IMyInjectableType) {
super();
}

// ...
}
example

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$);
}
};
example
@extension()
export class MyCardUIExtension extends CardUIExtension {
constructor(
@inject(IMyInjectableType$, { optional: true })
private readonly _myType: IMyInjectableType | null
) {
super();
}

// ...
}

Namespaces

DI_Interfaces
DiHelper

Classes

BindingScope
DiContainer
LazyServiceIdentifier

Functions

createInjectToken
inject
injectable
isInjectToken
unmanaged
MMNEPVFCICPMFPCPTTAAATR