@@ -35,6 +35,8 @@ These utilities provide a declarative way to define Express routes, middleware,
3535- [ ** ` @Version(version: string, options?: VersionOptions): MethodDecorator ` ** ] ( #version ) - Add API versioning to routes.
3636- [ ** ` @Timeout(ms: number): MethodDecorator ` ** ] ( #timeout ) - Set execution timeout for routes.
3737- [ ** ` @Log(options?: LogOptions): MethodDecorator ` ** ] ( #log ) - Add comprehensive logging to routes.
38+ - [ ** ` @Injectable(): ClassDecorator ` ** ] ( #injectable ) - Mark a class as injectable for DI.
39+ - [ ** ` @Inject(targetClass: Constructor): PropertyDecorator ` ** ] ( #inject ) - Inject a dependency into a class property.
3840
3941---
4042
@@ -52,6 +54,7 @@ These decorators and utilities allow you to:
5254- Add caching, rate limiting, versioning, and timeout handling.
5355- Implement comprehensive logging and response customization.
5456- Register controller classes with an Express router.
57+ - Use dependency injection for services and controllers.
5558
5659---
5760
@@ -1061,6 +1064,76 @@ getPublicStats() {
10611064
10621065---
10631066
1067+ ### ` @Injectable() `
1068+ Marks a class as injectable for dependency injection.
1069+
1070+ ** Method Signature:**
1071+ ``` ts
1072+ @Injectable (): ClassDecorator
1073+ ```
1074+
1075+ ** Returns:**
1076+ - A class decorator.
1077+
1078+ ** Examples:**
1079+ ``` ts
1080+ import { Injectable } from ' @catbee/utils' ;
1081+
1082+ @Injectable ()
1083+ class UserService {
1084+ findAll() { /* ... */ }
1085+ }
1086+ ```
1087+
1088+ ---
1089+
1090+ ### ` @Inject() `
1091+ Injects a dependency into a class property or via constructor.
1092+
1093+ ** Method Signature:**
1094+ ``` ts
1095+ @Inject (targetClass : Constructor ): PropertyDecorator
1096+ ```
1097+
1098+ ** Parameters:**
1099+ - ` targetClass ` : The class to inject.
1100+
1101+ ** Returns:**
1102+ - A property decorator.
1103+
1104+ ** Examples (Property Injection):**
1105+ ``` ts
1106+ import { Injectable , Inject , Controller } from ' @catbee/utils' ;
1107+
1108+ @Injectable ()
1109+ class UserService {
1110+ getUser() { /* ... */ }
1111+ }
1112+
1113+ @Controller (' /api/users' )
1114+ class UserController {
1115+ @Inject (UserService )
1116+ userService! : UserService ;
1117+ }
1118+ ```
1119+
1120+ ** Examples (Constructor Injection):**
1121+ ``` ts
1122+ import { Injectable , Controller } from ' @catbee/utils' ;
1123+
1124+ @Injectable ()
1125+ class UserService {
1126+ getUser() { /* ... */ }
1127+ }
1128+
1129+ @Controller (' /api/users' )
1130+ class UserController {
1131+ constructor (public userService : UserService ) {}
1132+ }
1133+ ```
1134+
1135+ ---
1136+
10641137## Controller-Level Decorator Inheritance
10651138
10661139Many decorators can be applied at the controller level and will be inherited by all methods in that controller, unless overridden at the method level.
0 commit comments