Central to ASP.NET Core is DI. The framework provides built-in DI services to allow developers to create loosely coupled applications and prevent instantiation or construction of dependencies. Using the built-in DI services, your application code can be set up to use DI, and dependencies can be injected into methods in the Startup class. While the default DI container has some cool features, you can still use other known, matured DI containers in ASP.NET core applications.
You can configure your code to use DI in two modes:
- Constructor Injection: The interfaces required by a class are passed or injected via the class's public constructor. Constructor injection is not possible using a private constructor, an InvalidOperationException will be thrown when this is attempted. In a class with an overloaded constructor, only one of...