Dependency injection
Vona injects Bean instances through @Use decorator function
Injection methods
Module Injection: Can be directly injected based onClass typeCross-Module Injection: Can be injected based onBean identifier, which helps achieve loose coupling between modules and supports circular references
Based on Class type
Inject the ServiceStudent provided by the module demo-student in the current module. The code is as follows:
typescript
import { ServiceStudent } from '../service/student.ts';
export class ControllerStudent {
@Use()
student: ServiceStudent;
}Based on Bean identifier
Inject the ServiceStudent provided by the module demo-student into other modules, as shown in the code below:
typescript
import type { ServiceStudent } from 'vona-module-demo-student';
export class ControllerStudent {
@Use('demo-student.service.student')
student: ServiceStudent;
}Since the imported ServiceStudent is of type, the Bean identifier of the Service needs to be specified