egg-aop
Add DI, AOP support for eggjs.
DI
Quick overview
import { Service, Context } from 'egg';
import { context, lazyInject } from 'egg-aop';
@context()
export class TestService extends Service {
get() {
}
}
export class Controller {
@lazyInject()
private testService: TestService;
demo() {
this.testService.get();
}
}
API
decoratros
@context(keyType?: any)
@application(keyType?: any)
@inject(keyType?: any)
@lazyInject(keyType?: any)
functions
getInstance<T = any>(clsType: any, app: any, ctx: any): T
setCreateInstanceHook(func: CreateInstanceHookFunction)
typeLoader
AOP
Quick overview
function logging(type: string) {
return aspect({
before: (inst, args) => { },
after: (inst, ret) => { },
onError: (inst, err) => { },
})
}
class DemoService {
@logging('create')
createData() {
}
}
API
functions
aspect<T = any>(point: AspectPoint<T> = {})