Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have an easy way to use abstract services #758

Closed
LoicPoullain opened this issue Jul 14, 2020 · 1 comment
Closed

Have an easy way to use abstract services #758

LoicPoullain opened this issue Jul 14, 2020 · 1 comment

Comments

@LoicPoullain
Copy link
Member

Issue

In some situations, we'd like to define an abstract service and choose which concrete service to use in the configuration depending on the environment.

Solution

logger:
  driver: 'my-package'

# OR

logger:
  driver: ./services/advanced-logger

logger.service.ts

export abstract class Logger {
  static concreteClassConfigPath = 'logger.driver';
  static concreteClassName = 'ConcreteLogger';

  abstract log(str: string): string;
}

advanced-logger.service.ts

export class AdvancedLogger extends Logger {
  log(str: string): string {
    console.log(str);
  }
}

export { AdvancedLogger as ConcreteLogger };

a random service

export class Service {
  @dependency
  logger: Logger;

  // ...
}
@LoicPoullain LoicPoullain added this to Work In Progress in Issue tracking Jul 14, 2020
Issue tracking automation moved this from Work In Progress to Backlog Jul 14, 2020
@LoicPoullain LoicPoullain moved this from Backlog to Work In Progress in Issue tracking Jul 16, 2020
@LoicPoullain
Copy link
Member Author

Feature added in v1.10.0

Issue tracking automation moved this from Work In Progress to Done / Closed This Release Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Issue tracking
  
Done / Closed This Release
Development

No branches or pull requests

1 participant