useClass tạo instance từ class cụ thể, thường để đổi implementation.
Ví dụ các provider strategy:
typescript
providers: [
{ provide: Logger, useClass: ConsoleLogger },
{ provide: API_URL, useValue: "/api" },
{ provide: SESSION_ID, useFactory: () => crypto.randomUUID() },
{ provide: OLD_LOGGER, useExisting: Logger },
]useValue cấp object/value có sẵn, useFactory tạo dependency động và có thể inject dependency khác, useExisting alias token này sang token khác để reuse cùng instance.
useClass creates an instance from a concrete class, often to swap implementations.
Provider strategy examples:
typescript
providers: [
{ provide: Logger, useClass: ConsoleLogger },
{ provide: API_URL, useValue: "/api" },
{ provide: SESSION_ID, useFactory: () => crypto.randomUUID() },
{ provide: OLD_LOGGER, useExisting: Logger },
]useValue provides an existing object/value, useFactory creates a dynamic dependency and can inject other dependencies, and useExisting aliases one token to another to reuse the same instance.