Providers

Providers are implementations of services that assist in the business rules of your project. They can contain one or more implementations, you decide which one to use, to switch the key in .env.

To use a provider in your business logic, simply inject your token with tsyinge:

import { IProvider } from '@shared/container/providers/Provider/models/IProvider';
import { injectable, inject } from 'tsyringe';

@injectable()
export class ExampleService {
  public constructor(
    @inject('Provider')
    private readonly provider: IProvider,
  ) {}

  public async execute(): Promise<void> {
    try {
      this.provider.doSomething();
    } catch (error: unknown) {
      throw error;
    }
  }
}

Last updated