Level: Introductory / Intermediate
Most developers are introduced to dependency injection (DI) completely backwards: they are given an application that already uses dependency injection and told "Good Luck". But it is really hard to get the benefits from DI if you do not exactly understand what it is and, more importantly, why you want to use it. Let's change that. In this session, you will see problems that are caused by tightly-coupled code. You will see how dependency injection can break that coupling. And you will see how loosely-coupled code is ultimately easier to extend and test. Along the way you will see some DI patterns such as constructor injection, and you will get a better understanding of what a DI container does. With these skills in hand, you can use dependency injection to make your own code easier to extend and test.
- Slides: SLIDES-DependencyInjection.pdf
- Completed Code: /Completed
DI Patterns
- Dependency Injection: The Property Injection Pattern
- Property Injection: Simple vs. Safe
- Dependency Injection: The Service Locator Pattern
Decorators and Async Interfaces
- Async Interfaces, Decorators, and .NET Standard
- Async Interfaces
- Adding Retry with the Decorator Pattern
- Unit Testing Async Methods
- Adding Exception Logging with the Decorator Pattern
- Adding a Client-Side Cache with the Decorator Pattern
- The Real Power of Decorators -- Stacking Functionality
Challenges
- Static Objects: Mocking Current Time with a Simple Time Provider
Other Resources
- Steve Smith: New is Glue
Other Topics
- Topic: IEnumerable, ISaveable, IDontGetIt: Understanding C# Interfaces
- Topic: Abstract Art: Getting Abstraction "Just Right"
- Article: Do I Really Need a Repository?