Setting up a DI container for ASP.NET Core MVC

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 ...

Get C# and .NET Core Test Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.