Code to Understand C# Dependency Injection
Quick planning post to write code to understand the C# dependency injection magic.
Plan is to:
- Write a library with one function that reverses a string
- Write a console app that takes a string and applies the injected transformation on it
- Use the dependency injection framework to inject the function reverse method into it
- Write another function that capitalises the string
- Change the dependency injection to use the capitalisation
This hands-on approach should demonstrate how DI works by building a simple string transformation pipeline where the specific transformation can be swapped out via dependency injection.
The example will use Microsoft.Extensions.DependencyInjection - the standard DI container for .NET applications.