如何从 givin 实体注入存储库

how can I inject a repository from a givin entity

提问人:Sherif eldeeb 提问时间:11/9/2023 更新时间:11/9/2023 访问量:20

问:

我正在将 Nestjs 与 TypeORM 一起使用,我想创建一个接收实体并从中创建存储库的类(不提供默认数据源)

在 Nestjs 中,我们可以像这样注入存储库

@Injectable()
export class MyService {
  constructor(
    @InjectRepository(MyEntity)
    private repo: Repository<MyEntity>
  ) {}
}

我想做这样的事情:

@Injectable()
export class MyRepository<Entity extends EntityClassOrSchema> {
  constructor(
    private entity: Entity,
    // this.entity here has not defined yet
    @InjectRepository(this.entity) private repo: Repository<Entity>
  ) {}
}
nestjs typeorm nestjs-typeorm

评论


答: 暂无答案