English
Topic 6. Dependency injection, configuration, and logging in .NET applications
Goal: become familiar with the dependency inversion principle and the Microsoft.Extensions.DependencyInjection container; learn to register services with different lifetimes, read settings from appsettings.json, environment variables, the command line, and user secrets, and use the options pattern with validation and the ILogger<T> logger; master creating console hosts with background services, dependency injection in Windows Forms, and unit testing of services with fake dependencies.
Lecture contents
- Dependency injection and the container — Dependencies and their injection · The Microsoft.Extensions.DependencyInjection container · Service lifetimes
- The host, configuration, and options — The .NET Generic Host · Configuration · User secrets · The options pattern
- Logging — Logging
- DI in Windows Forms and testability — Dependency injection in Windows Forms · Testability
- Common mistakes — Common mistakes