eggjs/egg-aop

Name: egg-aop

Owner: egg

Description: AOP plugin for eggjs, add DI, AOP support.

Created: 2018-03-15 06:38:39.0

Updated: 2018-05-07 17:20:49.0

Pushed: 2018-04-19 11:50:50.0

Homepage:

Size: 67

Language: TypeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

egg-aop

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Add DI, AOP support for eggjs.

DI
Quick overview
rt { Service, Context } from 'egg';
rt { context, lazyInject } from 'egg-aop';

text() // or @application()
rt class TestService extends Service {
t() {
/* code */



rt class Controller {
azyInject()
ivate testService: TestService;

mo() {
this.testService.get();


API
decoratros functions typeLoader

typeLoader is a instance of IocContext, this stored all type's classes. You can use this to affect DI behavior.

AOP
Quick overview
tion logging(type: string) {
turn aspect({
// before method running
before: (context) => { /* log code */ },
// after method running
after: (context) => { /* log code */ },
// when method throw error
onError: (context) => { /* log code */ },



s DemoService {
ogging('create')
eateData() {
/* code */



unctionContext type define */
rt interface FunctionContext<T = any> {
adonly inst: T;
adonly functionName: string;
gs: any[];
t: any;
r: Error;

API
functions

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.