Created
August 12, 2022 08:57
-
-
Save hongphuc5497/8ce42e554cb23f136d55d63428211313 to your computer and use it in GitHub Desktop.
Dependency Injection
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
// 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