Repository: artusjs/core
Pull request #145 (2022-07-15 07:01:25)

feat: support inject in lifecycle
ref: https://github.com/artusjs/core/issues/143

JerrysShan: 之前专门为 lifecycle 实现的装饰器貌似可以移除了 
hyj1991: > 之前专门为 lifecycle 实现的装饰器貌似可以移除了

现在是存储 lifecycle 的 class 吧？看起来不能移除
JerrysShan: 




> 现在是存储 lifecycle 的 class 吧？看起来不能移除

WithApplication , WithContainer 这几个好像是 lifecycyle 专用吧

hyj1991: 对，这两个是可以去掉了，稍后我再改下
JerrysShan: 这个进度如何了，什么时候可以合并
codecov-commenter: # [Codecov](https://codecov.io/gh/artusjs/core/pull/145?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#145](https://codecov.io/gh/artusjs/core/pull/145?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (138e8fb) into [master](https://codecov.io/gh/artusjs/core/commit/6945a13872068592600732eaa9e48b5ede5ee3de?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (6945a13) will **decrease** coverage by `0.37%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master     #145      +/-   ##
==========================================
- Coverage   89.44%   89.06%   -0.38%     
==========================================
  Files          51       51              
  Lines        1108     1107       -1     
  Branches      182      181       -1     
==========================================
- Hits          991      986       -5     
- Misses        117      121       +4     
```


| [Impacted Files](https://codecov.io/gh/artusjs/core/pull/145?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [src/constant.ts](https://codecov.io/gh/artusjs/core/pull/145/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL2NvbnN0YW50LnRz) | `100.00% <ø> (ø)` | |
| [src/lifecycle/index.ts](https://codecov.io/gh/artusjs/core/pull/145/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL2xpZmVjeWNsZS9pbmRleC50cw==) | `82.35% <100.00%> (-0.99%)` | :arrow_down: |
| [src/loader/impl/lifecycle.ts](https://codecov.io/gh/artusjs/core/pull/145/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL2xvYWRlci9pbXBsL2xpZmVjeWNsZS50cw==) | `100.00% <100.00%> (ø)` | |
| [src/decorator.ts](https://codecov.io/gh/artusjs/core/pull/145/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL2RlY29yYXRvci50cw==) | `80.00% <0.00%> (-16.00%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/artusjs/core/pull/145?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/artusjs/core/pull/145?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Last update [6945a13...138e8fb](https://codecov.io/gh/artusjs/core/pull/145?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).

hyj1991: cc @noahziheng @JerrysShan ，合并了 master，去除了 `WithXXX` 的 API 已经更新了对应的 test case
hyj1991: 我确认下 lazy set 如何实现的

Patch:
diff --git a/package.json b/package.json
index 70da73a..c5680da 100644
--- a/package.json
+++ b/package.json
@@ -63,7 +63,7 @@
     "typescript": "^4.7.2"
   },
   "dependencies": {
-    "@artus/injection": "^0.4.0",
+    "@artus/injection": "^0.4.1",
     "@artus/pipeline": "^0.2.2",
     "deepmerge": "^4.2.2",
     "minimatch": "^5.0.1"
diff --git a/src/constant.ts b/src/constant.ts
index cd84884..51be2b3 100644
--- a/src/constant.ts
+++ b/src/constant.ts
@@ -25,10 +25,6 @@ export enum ARTUS_DEFAULT_CONFIG_ENV {
 }
 
 export const HOOK_NAME_META_PREFIX = 'hookName:';
-export const CONSTRUCTOR_PARAMS = 'constructor:params';
-export const CONSTRUCTOR_PARAMS_APP = 'constructor:params:app';
-export const CONSTRUCTOR_PARAMS_CONTAINER = 'constructor:params:container';
-export const CONSTRUCTOR_PARAMS_CONTEXT = 'constructor:params:context';
 export const HOOK_FILE_LOADER = 'appHook:fileLoader';
 export const HOOK_CONFIG_HANDLE = 'appHook:configHandle::';
 
@@ -54,12 +50,12 @@ export const EXCEPTION_FILENAME = 'exception.json';
 export const DEFAULT_LOADER_LIST_WITH_ORDER = [
   'exception',
   'plugin-config',
-  'lifecycle-hook-unit',
-  'config',
   'plugin-meta',
-  'module',
   'framework-config',
   'package-json',
+  'module',
+  'lifecycle-hook-unit',
+  'config',
 ];
 
 export const DEFAULT_CONFIG_DIR = 'src/config';
diff --git a/src/decorator.ts b/src/decorator.ts
index 33bed41..a8484a0 100644
--- a/src/decorator.ts
+++ b/src/decorator.ts
@@ -1,16 +1,13 @@
+import { Injectable } from '@artus/injection';
 import {
-  CONSTRUCTOR_PARAMS,
-  CONSTRUCTOR_PARAMS_APP,
-  CONSTRUCTOR_PARAMS_CONTAINER,
   HOOK_NAME_META_PREFIX,
-  CONSTRUCTOR_PARAMS_CONTEXT,
   HOOK_FILE_LOADER,
 } from './constant';
 
 export function LifecycleHookUnit(): ClassDecorator {
   return (target: any) => {
-    // Ready to remove?
     Reflect.defineMetadata(HOOK_FILE_LOADER, { loader: 'lifecycle-hook-unit' }, target);
+    Injectable({ lazy: true })(target);
   };
 }
 
@@ -23,29 +20,5 @@ export function LifecycleHook(hookName?: string): PropertyDecorator {
   };
 }
 
-const WithConstructorParams = (tag: string): ParameterDecorator => {
-  return (target: any, _propertyKey: string | symbol, parameterIndex: number) => {
-    const paramsMd = Reflect.getOwnMetadata(CONSTRUCTOR_PARAMS, target) ?? [];
-    paramsMd[parameterIndex] = tag;
-    if (_propertyKey) {
-      Reflect.defineMetadata(CONSTRUCTOR_PARAMS, paramsMd, target[_propertyKey]); // for proto
-    } else {
-      Reflect.defineMetadata(CONSTRUCTOR_PARAMS, paramsMd, target); // for constructor
-    }
-  };
-};
-
-export function WithApplication(): ParameterDecorator {
-  return WithConstructorParams(CONSTRUCTOR_PARAMS_APP);
-}
-
-export function WithContainer(): ParameterDecorator {
-  return WithConstructorParams(CONSTRUCTOR_PARAMS_CONTAINER);
-}
-
-export function WithContext(): ParameterDecorator {
-  return WithConstructorParams(CONSTRUCTOR_PARAMS_CONTEXT);
-}
-
 export * from './loader/decorator';
 export * from './trigger/decorator';
diff --git a/src/index.ts b/src/index.ts
index f79718f..efebf7d 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,9 +1,4 @@
-
-
-export {
-  Inject,
-  Injectable,
-} from '@artus/injection';
+export * from '@artus/injection';
 
 export * from './loader';
 export * from './logger';
diff --git a/src/lifecycle/index.ts b/src/lifecycle/index.ts
index c3b7e48..e86680d 100644
--- a/src/lifecycle/index.ts
+++ b/src/lifecycle/index.ts
@@ -1,17 +1,14 @@
 import { Constructable, Container } from '@artus/injection';
 import { Application } from '../types';
 import {
-  CONSTRUCTOR_PARAMS,
-  CONSTRUCTOR_PARAMS_APP,
-  CONSTRUCTOR_PARAMS_CONTAINER,
   HOOK_NAME_META_PREFIX,
 } from '../constant';
 
-export type HookFunction = <T = unknown>(hookProps : {
+export type HookFunction = <T = unknown>(hookProps: {
   app: Application,
   lifecycleManager: LifecycleManager,
   payload?: T
-}) => void|Promise<void>;
+}) => void | Promise<void>;
 
 export class LifecycleManager {
   hookList: string[] = [
@@ -52,12 +49,7 @@ export class LifecycleManager {
 
   registerHookUnit(extClazz: Constructable<any>) {
     const fnMetaKeys = Reflect.getMetadataKeys(extClazz);
-    const constructorParams = Reflect.getMetadata(CONSTRUCTOR_PARAMS, extClazz) ?? [];
-    const paramsMap = {
-      [CONSTRUCTOR_PARAMS_APP]: this.app,
-      [CONSTRUCTOR_PARAMS_CONTAINER]: this.container,
-    };
-    const extClazzInstance = new extClazz(...constructorParams.map(param => paramsMap[param]));
+    const extClazzInstance = this.container.get(extClazz);
     for (const fnMetaKey of fnMetaKeys) {
       if (typeof fnMetaKey !== 'string' || !fnMetaKey.startsWith(HOOK_NAME_META_PREFIX)) {
         continue;
diff --git a/src/loader/impl/lifecycle.ts b/src/loader/impl/lifecycle.ts
index a02ec97..c1e672d 100644
--- a/src/loader/impl/lifecycle.ts
+++ b/src/loader/impl/lifecycle.ts
@@ -17,6 +17,7 @@ class LifecycleLoader implements Loader {
   async load(item: ManifestItem) {
     const extClazz: Constructable<ApplicationLifecycle> = await compatibleRequire(item.path);
     const lifecycleManager: LifecycleManager = this.container.get(ArtusInjectEnum.LifecycleManager);
+    this.container.set({ type: extClazz });
     lifecycleManager.registerHookUnit(extClazz);
     return extClazz;
   }


Test patch:
diff --git a/test/fixtures/app_koa_with_ts/src/app.ts b/test/fixtures/app_koa_with_ts/src/app.ts
index f9bcba6..ff819c6 100644
--- a/test/fixtures/app_koa_with_ts/src/app.ts
+++ b/test/fixtures/app_koa_with_ts/src/app.ts
@@ -1,10 +1,10 @@
 import { DefaultContext } from 'koa';
 import { Server } from 'http';
-import { Container } from '@artus/injection';
+import { Container, Inject } from '@artus/injection';
 import { Context, Input } from '@artus/pipeline';
 
-import { ArtusApplication } from '../../../../src';
-import { LifecycleHookUnit, LifecycleHook, WithApplication, WithContainer } from '../../../../src/decorator';
+import { ArtusApplication, ArtusInjectEnum } from '../../../../src';
+import { LifecycleHookUnit, LifecycleHook } from '../../../../src/decorator';
 import { ApplicationLifecycle } from '../../../../src/types';
 
 import KoaApplication from './koa_app';
@@ -14,14 +14,11 @@ export let server: Server;
 
 @LifecycleHookUnit()
 export default class MyLifecycle implements ApplicationLifecycle {
+  @Inject(ArtusInjectEnum.Application)
   app: ArtusApplication;
+  @Inject()
   container: Container;
 
-  constructor(@WithApplication() app: ArtusApplication, @WithContainer() container: Container) {
-    this.app = app;
-    this.container = container;
-  }
-
   get koaApp(): KoaApplication {
     return this.container.get(KoaApplication);
   }
diff --git a/test/fixtures/artus_application/src/controller/conifg.ts b/test/fixtures/artus_application/src/controller/conifg.ts
index fe51331..be9cca0 100644
--- a/test/fixtures/artus_application/src/controller/conifg.ts
+++ b/test/fixtures/artus_application/src/controller/conifg.ts
@@ -1,6 +1,5 @@
 import { Context } from '@artus/pipeline';
 import { HttpController, HttpMethod, HTTPMethodEnum } from '../../../frameworks/bar/src';
-import { WithContext } from '../../../../../src/decorator';
 
 @HttpController()
 export default class Hello {
@@ -8,7 +7,7 @@ export default class Hello {
     method: HTTPMethodEnum.GET,
     path: '/config',
   })
-  async index(@WithContext() ctx: Context) {
+  async index(ctx: Context) {
     const { params: { config } } = ctx.input;
     return {
       message: `get conifg succeed`,
diff --git a/test/fixtures/artus_application/src/controller/hello.ts b/test/fixtures/artus_application/src/controller/hello.ts
index 71393e8..9b95419 100644
--- a/test/fixtures/artus_application/src/controller/hello.ts
+++ b/test/fixtures/artus_application/src/controller/hello.ts
@@ -1,6 +1,5 @@
 import { Context } from '@artus/pipeline';
 import { HttpController, HttpMethod, HTTPMethodEnum } from '../../../frameworks/bar/src';
-import { WithContext } from '../../../../../src/decorator';
 
 @HttpController()
 export default class Hello {
@@ -8,7 +7,7 @@ export default class Hello {
     method: HTTPMethodEnum.GET,
     path: '/home',
   })
-  async index(@WithContext() ctx: Context) {
+  async index(ctx: Context) {
     const { params: { config } } = ctx.input;
     return { title: `Hello Artus ${config.name}` };
   }
@@ -17,7 +16,7 @@ export default class Hello {
     method: HTTPMethodEnum.GET,
     path: '/get_name2',
   })
-  async name2(@WithContext() ctx: Context) {
+  async name2(ctx: Context) {
     const { params: { config } } = ctx.input;
     return { title: `Hello Artus ${config.name2}` };
   }
@@ -26,7 +25,7 @@ export default class Hello {
     method: HTTPMethodEnum.GET,
     path: '/get_name3',
   })
-  async name3(@WithContext() ctx: Context) {
+  async name3(ctx: Context) {
     const { params: { config } } = ctx.input;
     return { title: `Hello Artus ${config.name3}` };
   }
diff --git a/test/fixtures/artus_application/src/controller/plugin.ts b/test/fixtures/artus_application/src/controller/plugin.ts
index 5735895..5b0bacf 100644
--- a/test/fixtures/artus_application/src/controller/plugin.ts
+++ b/test/fixtures/artus_application/src/controller/plugin.ts
@@ -1,6 +1,5 @@
 import { HttpController, HttpMethod, HTTPMethodEnum } from '../../../frameworks/bar/src';
 import { Inject } from '@artus/injection';
-import { WithContext } from '../../../../../src/decorator';
 import { ArtusApplication } from '../../../../../src';
 import { Context } from '@artus/pipeline';
 
@@ -23,7 +22,7 @@ export default class Hello {
     method: HTTPMethodEnum.GET,
     path: '/plugin-redis',
   })
-  async getRedisClient(@WithContext() ctx: Context) {
+  async getRedisClient(ctx: Context) {
     const app: ArtusApplication = ctx.input.params.app;
     let client;
     try {
diff --git a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/app.ts b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/app.ts
index be128f0..32c6ae0 100644
--- a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/app.ts
+++ b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/src/app.ts
@@ -1,19 +1,16 @@
 import { Server } from 'http';
-import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../../../../src/decorator';
+import { LifecycleHookUnit, LifecycleHook } from '../../../../../../../src/decorator';
 import { ApplicationLifecycle } from '../../../../../../../src/types';
-import { ArtusApplication } from '../../../../../../../src';
+import { ArtusApplication, Inject, ArtusInjectEnum } from '../../../../../../../src';
 import Client, { MysqlConfig } from './client';
 
 export let server: Server;
 
 @LifecycleHookUnit()
 export default class MyLifecycle implements ApplicationLifecycle {
+  @Inject(ArtusInjectEnum.Application)
   app: ArtusApplication;
 
-  constructor(@WithApplication() app: ArtusApplication) {
-    this.app = app;
-  }
-
   @LifecycleHook()
   async willReady() {
     const mysql = this.app.container.get('ARTUS_MYSQL') as Client;
diff --git a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/app.ts b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/app.ts
index be128f0..32c6ae0 100644
--- a/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/app.ts
+++ b/test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/src/app.ts
@@ -1,19 +1,16 @@
 import { Server } from 'http';
-import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../../../../src/decorator';
+import { LifecycleHookUnit, LifecycleHook } from '../../../../../../../src/decorator';
 import { ApplicationLifecycle } from '../../../../../../../src/types';
-import { ArtusApplication } from '../../../../../../../src';
+import { ArtusApplication, Inject, ArtusInjectEnum } from '../../../../../../../src';
 import Client, { MysqlConfig } from './client';
 
 export let server: Server;
 
 @LifecycleHookUnit()
 export default class MyLifecycle implements ApplicationLifecycle {
+  @Inject(ArtusInjectEnum.Application)
   app: ArtusApplication;
 
-  constructor(@WithApplication() app: ArtusApplication) {
-    this.app = app;
-  }
-
   @LifecycleHook()
   async willReady() {
     const mysql = this.app.container.get('ARTUS_MYSQL') as Client;
diff --git a/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/app.ts b/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/app.ts
index 72f1dba..0dd866e 100644
--- a/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/app.ts
+++ b/test/fixtures/artus_application/src/plugins/artus_plugin_redis/src/app.ts
@@ -1,19 +1,16 @@
 import { Server } from 'http';
-import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../../../../src/decorator';
+import { LifecycleHookUnit, LifecycleHook } from '../../../../../../../src/decorator';
 import { ApplicationLifecycle } from '../../../../../../../src/types';
-import { ArtusApplication } from '../../../../../../../src';
+import { ArtusApplication, Inject, ArtusInjectEnum } from '../../../../../../../src';
 import Client, { RedisConfig } from './client';
 
 export let server: Server;
 
 @LifecycleHookUnit()
 export default class MyLifecycle implements ApplicationLifecycle {
+  @Inject(ArtusInjectEnum.Application)
   app: ArtusApplication;
 
-  constructor(@WithApplication() app: ArtusApplication) {
-    this.app = app;
-  }
-
   @LifecycleHook()
   async willReady() {
     const redis = this.app.container.get('ARTUS_REDIS') as Client;
diff --git a/test/fixtures/custom_instance/bootstrap.ts b/test/fixtures/custom_instance/bootstrap.ts
index c766784..83fdcb4 100644
--- a/test/fixtures/custom_instance/bootstrap.ts
+++ b/test/fixtures/custom_instance/bootstrap.ts
@@ -1,22 +1,18 @@
 import {
   ArtusApplication,
-  ApplicationLifecycle, LifecycleHookUnit, LifecycleHook,
-  WithApplication, WithContainer,
+  ApplicationLifecycle, LifecycleHookUnit, LifecycleHook, ArtusInjectEnum,
 } from '../../../src/index';
 
-import { Container } from '@artus/injection';
+import { Container, Inject } from '@artus/injection';
 import Custom from './custom';
 
 @LifecycleHookUnit()
 export default class MyLifecycle implements ApplicationLifecycle {
+  @Inject(ArtusInjectEnum.Application)
   app: ArtusApplication;
+  @Inject()
   container: Container;
 
-  constructor(@WithApplication() app: ArtusApplication, @WithContainer() container) {
-    this.app = app;
-    this.container = container;
-  }
-
   @LifecycleHook()
   configDidLoad() {
     this.container.set({ id: Custom, value: new Custom('foo') });
diff --git a/test/fixtures/frameworks/bar/src/http.ts b/test/fixtures/frameworks/bar/src/http.ts
index 5f8ebf2..dd39f96 100644
--- a/test/fixtures/frameworks/bar/src/http.ts
+++ b/test/fixtures/frameworks/bar/src/http.ts
@@ -1,7 +1,6 @@
 import 'reflect-metadata';
 import { Context, Next } from '@artus/pipeline';
-import { Constructable , Injectable, ScopeEnum } from '@artus/injection';
-import { CONSTRUCTOR_PARAMS, CONSTRUCTOR_PARAMS_CONTEXT } from '../../../../../src/constant';
+import { Constructable, Injectable, ScopeEnum } from '@artus/injection';
 import { HttpTrigger } from '../../abstract/foo';
 
 export const enum HTTPMethodEnum {
@@ -72,11 +71,7 @@ export function registerController(trigger: HttpTrigger) {
         if (req.url === `${prefix}${path}` && req.method === method) {
           const instance: any = ctx.container.get(clazz);
           const target = instance[key];
-          const params: any = Reflect.getMetadata(CONSTRUCTOR_PARAMS, target) ?? [];
-          const paramsMap = {
-            [CONSTRUCTOR_PARAMS_CONTEXT]: ctx,
-          };
-          ctx.output.data.content = await target.call(instance, ...params.map(param => paramsMap[param]));
+          ctx.output.data.content = await target.call(instance, ctx);
         }
         await next();
       });
diff --git a/test/fixtures/frameworks/bar/src/lifecycle.ts b/test/fixtures/frameworks/bar/src/lifecycle.ts
index 024da8a..064cd19 100644
--- a/test/fixtures/frameworks/bar/src/lifecycle.ts
+++ b/test/fixtures/frameworks/bar/src/lifecycle.ts
@@ -1,7 +1,7 @@
 import { Server } from 'http';
-import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../../src/decorator';
+import { LifecycleHookUnit, LifecycleHook } from '../../../../../src/decorator';
 import { ApplicationLifecycle } from '../../../../../src/types';
-import { ArtusApplication } from '../../../../../src';
+import { ArtusInjectEnum, ArtusApplication, Inject } from '../../../../../src';
 import { registerController } from './/http';
 import { HttpTrigger } from '../../abstract/foo';
 
@@ -9,12 +9,9 @@ export let server: Server;
 
 @LifecycleHookUnit()
 export default class MyLifecycle implements ApplicationLifecycle {
+  @Inject(ArtusInjectEnum.Application)
   app: ArtusApplication;
 
-  constructor(@WithApplication() app: ArtusApplication) {
-    this.app = app;
-  }
-
   @LifecycleHook()
   async didLoad() {
     // register controller
diff --git a/test/fixtures/frameworks/layer/foo/foo1/src/lifecycle.ts b/test/fixtures/frameworks/layer/foo/foo1/src/lifecycle.ts
index 4a2bc17..7cde8b6 100644
--- a/test/fixtures/frameworks/layer/foo/foo1/src/lifecycle.ts
+++ b/test/fixtures/frameworks/layer/foo/foo1/src/lifecycle.ts
@@ -1,19 +1,16 @@
 import http, { Server } from 'http';
-import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../../../../src/decorator';
+import { LifecycleHookUnit, LifecycleHook } from '../../../../../../../src/decorator';
 import { ApplicationLifecycle } from '../../../../../../../src/types';
 import { Input } from '@artus/pipeline';
-import { ArtusApplication } from '../../../../../../../src';
+import { ArtusApplication, Inject, ArtusInjectEnum } from '../../../../../../../src';
 
 export let server: Server;
 
 @LifecycleHookUnit()
 export default class MyLifecycle implements ApplicationLifecycle {
+  @Inject(ArtusInjectEnum.Application)
   app: ArtusApplication;
 
-  constructor(@WithApplication() app: ArtusApplication) {
-    this.app = app;
-  }
-
   @LifecycleHook()
   willReady() {
     const config = this.app.config ?? {};
diff --git a/test/fixtures/frameworks/layer/foo/foo2/src/lifecycle.ts b/test/fixtures/frameworks/layer/foo/foo2/src/lifecycle.ts
index 4a2bc17..7cde8b6 100644
--- a/test/fixtures/frameworks/layer/foo/foo2/src/lifecycle.ts
+++ b/test/fixtures/frameworks/layer/foo/foo2/src/lifecycle.ts
@@ -1,19 +1,16 @@
 import http, { Server } from 'http';
-import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../../../../src/decorator';
+import { LifecycleHookUnit, LifecycleHook } from '../../../../../../../src/decorator';
 import { ApplicationLifecycle } from '../../../../../../../src/types';
 import { Input } from '@artus/pipeline';
-import { ArtusApplication } from '../../../../../../../src';
+import { ArtusApplication, Inject, ArtusInjectEnum } from '../../../../../../../src';
 
 export let server: Server;
 
 @LifecycleHookUnit()
 export default class MyLifecycle implements ApplicationLifecycle {
+  @Inject(ArtusInjectEnum.Application)
   app: ArtusApplication;
 
-  constructor(@WithApplication() app: ArtusApplication) {
-    this.app = app;
-  }
-
   @LifecycleHook()
   willReady() {
     const config = this.app.config ?? {};
diff --git a/test/fixtures/trigger/event/app.ts b/test/fixtures/trigger/event/app.ts
index a1f599c..d76b1ff 100644
--- a/test/fixtures/trigger/event/app.ts
+++ b/test/fixtures/trigger/event/app.ts
@@ -1,6 +1,6 @@
 import { EventEmitter } from 'events';
-import { ArtusApplication } from '../../../../src';
-import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../src/decorator';
+import { ArtusApplication, Inject, ArtusInjectEnum } from '../../../../src';
+import { LifecycleHookUnit, LifecycleHook } from '../../../../src/decorator';
 import { Context, Input, Next } from '@artus/pipeline';
 import { ApplicationLifecycle } from '../../../../src/types';
 
@@ -8,12 +8,9 @@ export const event = new EventEmitter();
 
 @LifecycleHookUnit()
 export default class MyLifecycle implements ApplicationLifecycle {
+  @Inject(ArtusInjectEnum.Application)
   app: ArtusApplication;
 
-  constructor(@WithApplication() app: ArtusApplication) {
-    this.app = app;
-  }
-
   @LifecycleHook()
   async didLoad() {
     this.app.trigger.use(async (ctx: Context, next: Next) => {
diff --git a/test/fixtures/trigger/http/app.ts b/test/fixtures/trigger/http/app.ts
index a8fd02b..88a2311 100644
--- a/test/fixtures/trigger/http/app.ts
+++ b/test/fixtures/trigger/http/app.ts
@@ -1,19 +1,16 @@
 import http, { Server } from 'http';
 import { Context, Input } from '@artus/pipeline';
-import { ArtusApplication } from '../../../../src';
-import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../src/decorator';
+import { ArtusApplication, Inject, ArtusInjectEnum } from '../../../../src';
+import { LifecycleHookUnit, LifecycleHook } from '../../../../src/decorator';
 import { ApplicationLifecycle } from '../../../../src/types';
 
 export let server: Server;
 
 @LifecycleHookUnit()
 export default class MyLifecycle implements ApplicationLifecycle {
+  @Inject(ArtusInjectEnum.Application)
   app: ArtusApplication;
 
-  constructor(@WithApplication() app: ArtusApplication) {
-    this.app = app;
-  }
-
   @LifecycleHook()
   async didLoad() {
     this.app.trigger.use(async (ctx: Context) => {
diff --git a/test/fixtures/trigger/timer/app.ts b/test/fixtures/trigger/timer/app.ts
index 33482dc..769e9ad 100644
--- a/test/fixtures/trigger/timer/app.ts
+++ b/test/fixtures/trigger/timer/app.ts
@@ -1,5 +1,5 @@
-import { ArtusApplication } from '../../../../src';
-import { LifecycleHookUnit, LifecycleHook, WithApplication } from '../../../../src/decorator';
+import { ArtusApplication, Inject, ArtusInjectEnum } from '../../../../src';
+import { LifecycleHookUnit, LifecycleHook } from '../../../../src/decorator';
 import { Context, Input } from '@artus/pipeline';
 import { ApplicationLifecycle } from '../../../../src/types';
 
@@ -17,12 +17,9 @@ export const execution = {
 
 @LifecycleHookUnit()
 export default class MyLifecycle implements ApplicationLifecycle {
+  @Inject(ArtusInjectEnum.Application)
   app: ArtusApplication;
 
-  constructor(@WithApplication() app: ArtusApplication) {
-    this.app = app;
-  }
-
   @LifecycleHook()
   async didLoad() {
     this.app.trigger.use(async (ctx: Context) => {
diff --git a/test/framework.test.ts b/test/framework.test.ts
index 26531a9..7f556d0 100644
--- a/test/framework.test.ts
+++ b/test/framework.test.ts
@@ -54,6 +54,5 @@ describe('test/framework.test.ts', () => {
 
     await app.artus.close();
     assert(!app.isListening());
-
   });
 });