update
This commit is contained in:
19
.roo/rules/06-service-di.md
Normal file
19
.roo/rules/06-service-di.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# 依赖注入规范
|
||||
|
||||
1. **依赖注入原则**
|
||||
- 服务类必须通过构造函数注入依赖
|
||||
- 禁止直接实例化全局对象(AppDataSource等)
|
||||
- 不需要import { Injectable } from '@nestjs/common';, 本项目没用@nestjs
|
||||
- 示例:
|
||||
```typescript
|
||||
// Good - 通过构造函数注入
|
||||
export class UserService {
|
||||
constructor(private dataSource: DataSource) {}
|
||||
}
|
||||
|
||||
// Bad - 使用全局实例
|
||||
export class UserService {
|
||||
constructor() {
|
||||
this.repository = AppDataSource.getRepository(User);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user