@Service
- @Service() — register an injectable service (singleton in the plugin DI container)
- List the class in @Module({ providers: [...] })
@Inject
Use property @Inject only — constructor injection is not supported. @Inject(Service) is same-plugin; @Inject(Service, "other-plugin") is cross-plugin.
- @Inject(MyService) — inject from the current plugin
- @Inject(MyService, "other-plugin") — inject from another plugin
TSXinject
1import {
2 Controller,
3 Inject,
4 PartnerService,
5} from "@quan-erp/shared-backend-core";
6import { RewardPointService } from "./reward-point.service.js";
7
8@Controller("/reward-point")
9export class RewardPointController {
10 @Inject(RewardPointService)
11 service: RewardPointService;
12
13 // cross-plugin
14 @Inject(PartnerService, "base")
15 partnerService: PartnerService;
16}Circular service injection
Mutual imports + @Inject(OtherService) can hit ESM TDZ. Use a lazy ref and InstanceType so design:type is not the class.
TSXlazy inject
1import { Inject, Service, UserService } from "@quan-erp/shared-backend-core";
2
3@Service()
4export class ChangeLogService {
5 @Inject(() => UserService)
6 userService: InstanceType<typeof UserService>;
7}Example
TSXservice
1import { Service } from "@quan-erp/shared-backend-core";
2
3@Service()
4export class LocationService {
5 async list() {
6 // domain logic
7 }
8}