{"id":41489181,"url":"https://github.com/eggjs/egg-aop","last_synced_at":"2026-01-23T18:16:12.875Z","repository":{"id":57131888,"uuid":"125323527","full_name":"eggjs/egg-aop","owner":"eggjs","description":"AOP plugin for eggjs, add DI, AOP support.","archived":false,"fork":false,"pushed_at":"2018-12-28T03:41:46.000Z","size":54,"stargazers_count":43,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-29T21:56:11.722Z","etag":null,"topics":["aop","di","egg","egg-plugin","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eggjs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-15T06:38:39.000Z","updated_at":"2024-09-07T07:07:04.000Z","dependencies_parsed_at":"2022-08-29T04:01:29.798Z","dependency_job_id":null,"html_url":"https://github.com/eggjs/egg-aop","commit_stats":null,"previous_names":["zhang740/egg-aop","zhang740/egg-typed-di"],"tags_count":31,"template":false,"template_full_name":null,"purl":"pkg:github/eggjs/egg-aop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-aop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-aop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-aop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-aop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eggjs","download_url":"https://codeload.github.com/eggjs/egg-aop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-aop/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28697428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T17:25:48.045Z","status":"ssl_error","status_checked_at":"2026-01-23T17:25:47.153Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aop","di","egg","egg-plugin","typescript"],"created_at":"2026-01-23T18:16:12.040Z","updated_at":"2026-01-23T18:16:12.863Z","avatar_url":"https://github.com/eggjs.png","language":"TypeScript","readme":"# egg-aop\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-aop.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-aop\n[travis-image]: https://img.shields.io/travis/eggjs/egg-aop.svg?style=flat-square\n[travis-url]: https://travis-ci.org/eggjs/egg-aop\n[codecov-image]: https://codecov.io/github/eggjs/egg-aop/coverage.svg?branch=master\n[codecov-url]: https://codecov.io/github/eggjs/egg-aop?branch=master\n[david-image]: https://img.shields.io/david/eggjs/egg-aop.svg?style=flat-square\n[david-url]: https://david-dm.org/eggjs/egg-aop\n[snyk-image]: https://snyk.io/test/npm/egg-aop/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-aop\n[download-image]: https://img.shields.io/npm/dm/egg-aop.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-aop\n\nAdd DI, AOP support for eggjs.\n\n## DI\n\n### Quick overview\n```ts\nimport { Service, Context } from 'egg';\nimport { context, lazyInject } from 'egg-aop';\n\n@context() // or @application()\nexport class TestService extends Service {\n  get() {\n    /* code */\n  }\n}\n\nexport class Controller {\n  @lazyInject()\n  private testService: TestService;\n  \n  demo() {\n    this.testService.get();\n  }\n}\n```\n\n### API\n\n#### decorators\n- `@context(keyType?: any)`\n\n  Declaration of life cycle of an instance, is context level. You can provide a class type or from metadata by TypeScript emit.\n  \n- `@application(keyType?: any)`\n\n  Declaration of life cycle of an instance, is context level. You can provide a class type or from metadata by TypeScript emit.\n\n- `@inject(keyType?: any)`\n\n  Inject component when the class is instantiated.\n\n- `@lazyInject(keyType?: any)`\n\n  Inject component when accessing the property.\n\n#### functions\n- `getInstance\u003cT = any\u003e(clsType: any, app: any, ctx: any): T`\n\n  You can use this function to manually get the component instance.\n\n- `setCreateInstanceHook(func: CreateInstanceHookFunction)`\n\n  You can use this function to interception every new component instance.\n\n  `type CreateInstanceHookFunction = (instance: any, app: any, ctx?: any) =\u003e any;`\n\n#### typeLoader\n\n`typeLoader` is an instance of `IocContext`, it stores all type's classes. You can use this to affect DI behavior.\n\n## AOP\n\n### Quick overview\n```ts\nfunction logging(type: string) {\n  return aspect({\n    // before method running\n    before: (context) =\u003e { /* log code */ },\n    // after method running\n    after: (context) =\u003e { /* log code */ },\n    // when method throw error\n    onError: (context) =\u003e { /* log code */ },\n  })\n}\n\nclass DemoService {\n  @logging('create')\n  createData() {\n    /* code */\n  }\n}\n\n/* FunctionContext type define */\nexport interface FunctionContext\u003cT = any\u003e {\n  readonly inst: T;\n  readonly functionName: string;\n  args: any[];\n  ret: any;\n  err: Error;\n}\n```\n\n### API\n\n#### functions\n- `aspect\u003cT = any\u003e(point: AspectPoint\u003cT\u003e = {})`\n\n  You can use this to intercept method, this function provides `before` / `after` / `error` cross-sections.\n\n  ```ts\n  interface AspectPoint\u003cT = any\u003e {\n    before?: (context: FunctionContext\u003cT\u003e) =\u003e void;\n    after?: (context: FunctionContext\u003cT\u003e) =\u003e void;\n    error?: (context: FunctionContext\u003cT\u003e) =\u003e void;\n  }\n  ```\n\n  The param `context` is the function's execution context. It includes `inst` / `args` / `ret`. You can replace them to affect the function execution.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-aop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feggjs%2Fegg-aop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-aop/lists"}