Last active
May 28, 2021 12:54
-
-
Save alissonfpmorais/06c2ff932e4d23d57ace387184e58135 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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