Home Update How to make use of Autofac in ASP.Net Core

How to make use of Autofac in ASP.Net Core

296


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.

  1. Launch the Visual Studio IDE.
  2. Click on “Create new project.”
  3. In the “Create new project” window, choose “ASP.Net Core Web Application” from the listing of the templates displayed.
  4. Click Next.
  5. In the “Configure your new project” window, specify the identify and site for the brand new venture.
  6. Click Create.
  7. 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.
  8. Select “Web Application” because the venture template. 
  9. Ensure that the test bins “Enable Docker Support” and “Configure for HTTPS” are unchecked as we received’t be utilizing these options right here.
  10. Ensure that Authentication is about as “No Authentication” as we received’t be utilizing authentication both.
  11. 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.



Source hyperlink

LEAVE A REPLY

Please enter your comment!
Please enter your name here