Skip to content

Instantly share code, notes, and snippets.

@alissonfpmorais
Last active May 28, 2021 12:54
Show Gist options
  • Save alissonfpmorais/06c2ff932e4d23d57ace387184e58135 to your computer and use it in GitHub Desktop.
Save alissonfpmorais/06c2ff932e4d23d57ace387184e58135 to your computer and use it in GitHub Desktop.
export class ChargeProcessorFactory {
static getProvider(): Provider<Promise<ChargeProcessor>> {
return {
// Interface
provide: ChargeProcessor,
// Factory que retorna implementação concreta
useFactory: async (gatewayService: GatewayService) => {
const billetGateways = await gatewayService.getGatewaysByPaymentMethod(BILLET_METHOD).toPromise();
const creditCardGateways = await gatewayService.getGatewaysByPaymentMethod(CREDIT_CARD_METHOD).toPromise();
const pixGateways = await gatewayService.getGatewaysByPaymentMethod(PIX_METHOD).toPromise();
return new ChargeProcessor(billetGateways, creditCardGateways, pixGateways);
},
// Provider a ser injetado para utilização na factory
inject: [GatewayService],
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment