Skip to content

Instantly share code, notes, and snippets.

@hongphuc5497
Created August 12, 2022 08:57
Show Gist options
  • Save hongphuc5497/8ce42e554cb23f136d55d63428211313 to your computer and use it in GitHub Desktop.
Save hongphuc5497/8ce42e554cb23f136d55d63428211313 to your computer and use it in GitHub Desktop.
Dependency Injection
// Examples of Dependency Injection
// Example 1
class LoggerConstructorInjection {
constructor(config) {
this.config = config;
}
getConfig() {
return this.config;
}
}
// Example 2
class LoggerSetterInjection {
constructor() {}
setConfig(config) {
this.config = config;
}
getConfig() {
return this.config;
}
}
// Example 3
class LoggerFieldInjection {
static config;
getConfig() {
return this.config;
}
setConfig(config) {
this.config = config;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment