黄骅市网站建设价格广告设计总结
黄骅市网站建设价格,广告设计总结,怎么做企业官方网站,网站正在建设中 给你带来局度慌钨VonaJS AOP编程
VonaJS AOP 编程包括三个方面的能力#xff1a;
控制器切面: 为 Controller 方法切入逻辑
内部切面: 在 Class 内部#xff0c;为任何 Class 的任何方法切入逻辑
外部切面: 在不改变 Class 源码的前提下#xff0c;从外部为任何 Class 的任何方法切入…局度慌钨VonaJS AOP编程VonaJS AOP 编程包括三个方面的能力控制器切面: 为 Controller 方法切入逻辑内部切面: 在 Class 内部为任何 Class 的任何方法切入逻辑外部切面: 在不改变 Class 源码的前提下从外部为任何 Class 的任何方法切入逻辑控制器切面控制器切面清单MiddlewareGuardIntercepterPipeFilter执行时序图控制器切面的执行时序图如下aspect-controller洋葱模型: Middleware和Intercepter支持洋葱模型允许在Controller Action之前和之后执行切面逻辑Middleware: 针对不同的执行时序节点系统提供了三种 Middleware: Middleware System、Middleware Global和Middleware Local从而可以实现更精细化的切面逻辑Route Match: 只有Middleware System在路由匹配之前执行其余在路由匹配之后执行Filter: 任何环节抛出异常都会执行Filter从而自定义错误信息和错误日志的处理逻辑内部切面内部切面提供两个机制AOP Method和魔术方法1. AOP Method直接在 Class Method 上通过装饰器切入逻辑举例数据库事务class ServiceStudent { Database.transaction()async update(id: TableIdentity, student: DtoStudentUpdate) {return await this.scope.model.student.updateById(id, student);}}Database.transaction通过AOP Method机制实现的装饰器可以直接提供数据库事务能力举例日志class ServiceStudent { Log()async update(id: TableIdentity, student: DtoStudentUpdate) {return await this.scope.model.student.updateById(id, student);}}Log通过AOP Method机制实现的装饰器可以直接提供日志能力2. 魔术方法可以在 Class 内部通过__get__和__set__切入动态属性或方法举例获取 model 实例class ServiceStudent {async update(id: TableIdentity, student: DtoStudentUpdate) { return await this.scope.model.student.updateById(id, student);}}this.scope.model.xxx: 没有使用依赖注入而是使用依赖查找直接通过 scope 对象获取 model 实例从而简化代码的书写风格实现思路系统提供了一个 Class ServiceModelResolver用于实现 model 实例的动态解析代码如下class ServiceModelResolver {protected __get__(prop: string) {const beanFullName ${this[SymbolModuleScope]}.model.${prop};return this.bean._getBean(beanFullName as any);}}当调用this.scope.model.student时会自动执行__get__方法并且传入参数prop: student将参数prop与当前模块名称合并成beanFullName通过beanFullName从全局容器中获取 model 实例并返回给调用者外部切面仍以 Class ServiceStudent的update方法为例通过外部切面来实现日志能力import { Aop } from vona-module-a-aspect;Aop({ match: demo-student.service.student })class AopLog {async update(_args: Parameters, next: Function, _receiver: any) {const timeBegin Date.now();const res await next();const timeEnd Date.now();console.log(time: , timeEnd - timeBegin);return res;}