Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
NestJS: ¿es diferente implementar el servicio de cliente sin OnModuleInit?

https://github.com/stephenh/ts-proto/blob/main/NESTJS.markdown

Del proyecto ts-proto, en el documento, veo que el cliente está implementado con OnModuleInit así

 import { HeroById, Hero, HeroServiceController, HeroesService, HERO_SERVICE_NAME, HERO_PACKAGE_NAME } from '../hero'; @Injectable() export class AppService implements OnModuleInit { private heroesService: HeroesService; constructor(@Inject(HERO_PACKAGE_NAME) private client: ClientGrpc) {} onModuleInit() { this.heroesService = this.client.getService<HeroesService>(HERO_SERVICE_NAME); } getHero(): Observable<Hero> { return this.heroesService.findOne({ id: 1 }); } }

Cambio el código sin OnModuleInit y funciona bien para mí

 import { HeroById, Hero, HeroServiceController, HeroesService, HERO_SERVICE_NAME, HERO_PACKAGE_NAME } from '../hero'; @Injectable() export class AppService { constructor(@Inject(HERO_PACKAGE_NAME) private client: ClientGrpc) {} private heroesService: HeroesService = this.client.getService<HeroesService>(HERO_SERVICE_NAME) getHero(): Observable<Hero> { return this.heroesService.findOne({ id: 1 }); } }

Entonces, ¿hay una diferencia potencial entre con o sin OnModuleInit?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda