Dependency injection facilitates unfastened coupling and promotes testability and upkeep. ASP.Net Core offers built-in assist for dependency injection (a type of inversion of management) with a minimalistic dependency injection container. However, the built-in container lacks lots of the options of a full-fledged dependency injection or inversion of management container.
To overcome this, you need to use third-party containers in ASP.Net Core. In different phrases, you’ll be able to simply change the built-in container with a third-party container. Autofac is an inversion of management container that can be utilized to resolve dependencies. This article offers a dialogue of how we are able to work with Autofac in ASP.Net Core.
Create an ASP.Net Core venture in Visual Studio
First let’s create an ASP.Net Core venture in Visual Studio. Assuming Visual Studio 2017 or Visual Studio 2019 is put in in your system, comply with the steps outlined under to create a brand new ASP.Net Core venture in Visual Studio.
- Launch the Visual Studio IDE.
- Click on “Create new project.”
- In the “Create new project” window, choose “ASP.Net Core Web Application” from the listing of the templates displayed.
- Click Next.
- In the “Configure your new project” window, specify the identify and site for the brand new venture.
- Click Create.
- In the “Create New ASP.Net Core Web Application” window, choose .Net Core because the runtime and ASP.Net Core 2.2 (or later) from the drop-down listing on the high.
- Select “Web Application” because the venture template.
- Ensure that the test bins “Enable Docker Support” and “Configure for HTTPS” are unchecked as we received’t be utilizing these options right here.
- Ensure that Authentication is about as “No Authentication” as we received’t be utilizing authentication both.
- Click Create.
This will create a brand new ASP.Net Core venture in Visual Studio. We’ll use this venture within the subsequent sections of this text to work with Autofac.