nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.05k stars 535 forks source link

[BREAKING CHANGE] `TypeOrmCrudService` should be a mixin class #209

Open BrunnerLivio opened 5 years ago

BrunnerLivio commented 5 years ago

Feature Request

The current implementation of extending a TypeOrmCrudService is cumbersome.

@Injectable()
export class HeroesService extends TypeOrmCrudService<Hero> {
  constructor(@InjectRepository(Hero) repo) {
    super(repo);
  }
}

By extending the TypeOrmCrudService, a user is forced to create a constructor and call the super-classes constructor. A user should not really have to care about this. This implementation also puts a @nestjsx/crud developer in a corner. When you introduce new dependencies which are needed for TypeOrmCrudService, you would need to force users to migrate and initialize a breaking change, because they would need to update their super-calls.

What we want to do, is having the TypeOrmCrudService to manage its dependencies itself, and therefore use the DI directly, without having the user to pass it through a super-call. The answer is mixins. You better watch this video from Kamil to see what is all about.

The new implementation would look like this:

@Injectable()
export class HeroesService extends TypeOrmCrudService(Hero) {
  // Wow much clean, very empty
}
hakimio commented 5 years ago

@zMotivat0r Any thoughts on this proposal?

Diluka commented 4 years ago

I have tried before. There is a problem I need to get metadata from typeorm and set it for nestjs and it is initializing when server starting. So I can't get metadata through static codes.

@BrunnerLivio You can make a technical example to get Hero metadata by extends SomeService(Hero)