Answers
- Transient, Scoped, Singleton.
- The composition root holds the code that describes how to compose the program’s object graph—the types bindings.
- Yes, it is true. Volatile dependencies should be injected instead of instantiated.
- The Strategy pattern.
- The Service Locator pattern is all three. It is a design pattern used by DI libraries internally but becomes a code smell in application code. If misused, it is an anti-pattern with the same drawbacks as using the
new
keyword directly. - The principle of composition over inheritance encourages us to inject dependencies into classes and use them instead of relying on base class features and inheritance. This approach promotes flexibility and code reuse. It also negates the need for the LSP.
Learn more on Discord
To join the Discord community for this book – where you can share feedback, ask questions to the author, and learn about new releases – follow the...