Dependency Injection in .NET
Here are some noteworthy takeaways from a course on Dependency Injection in .NET Core. DI Container Basics A container isn't a requirement but simplifies management of dependencies Services are registered at start up and resolve at runtime when they are required Container creates and disposes of instances while maintaining them for a specific lifetime Two primary interfaces for dependency injection in the .NET container IServicesCollection - registers and configures a service IServiceProvider - provides a mechanism for resolving a service at runtime Apply dependency via the constructor Register all services with the container Understand the service lifetimes Scoped Transient Singleton Identifying Dependencies to Register in the Container First, locate the new keyword usage. Is it the instance a dependency? If a class instantiates another class whose methods are used, it's a dependency. Repeat the above approach throughout your app code (there should be code...