#How to create an abstraction layer through interface to accept different implementation of provider

7 messages · Page 1 of 1 (latest)

low kiln
#

I am just beginning to test and experiment different use cases with nestjs. I have implementing a global mail service for my monolith backend. Whoever, I meant change they way I am handling mailing, e.g. right know I want to use Resend.com, although I might change back to nodemailer or a different SaaS mail provider.

The project is monolith and I have created a core feature library called "mail" which handles anything related mailing as I explained at above.

I want imports module or services based on the environment variables that are provided. I did a little bit of research and I came up with this solution of using useFactory to work out the strategy and decision making of which provider has to be provided for services.

#

I tried to get the env variables from ConfigService although I get the below error.

[Nest] 604405  - 05/05/2024, 11:03:56 PM   ERROR [ExceptionHandler] Cannot read properties of undefined (reading 'get')

TypeError: Cannot read properties of undefined (reading 'get')
    at InstanceWrapper.useFactory [as metatype] (./goran/dist/apps/api/main.js:1610:43)
    at Injector.instantiateClass
small lake
#

you missed the inject in your factory provider MAIL_PROVIDER

#

so config and resend are undefined because there's no way to nestjs to know what do you want

proud plover
low kiln