How to use Simple Injector in ASP.NET Core MVC


Dependency injection (also known as DI) is a design pattern in which an object receives the objects it depends on rather than creating them directly. Dependency injection facilitates loose coupling and promotes testability and easy maintenance. It allows you to change your implementations without changing the classes or interfaces that leverage those implementations.

Support for dependency injection is included in ASP.NET Core. As a result, you can inject both framework and application services into your classes rather than depend on tightly coupled components.

Simple Injector is a free, fast, and flexible inversion of control library that is easy to use and configure. It supports .NET Core, Xamarin, Mono, and Universal apps and is easily integrated with Web API, MVC, WCF, ASP.NET Core, etc.

This article talks about how we can leverage Simple Injector to implement dependency injection in ASP.NET Core MVC.

To work with the code examples provided in this article, you should have Visual Studio 2019 installed in your system. If you don’t already have a copy, you can download Visual Studio 2019 here.

Create an ASP.NET Core MVC project in Visual Studio 2019

First off, let’s create an ASP.NET Core MVC project in Visual Studio 2019. Following these steps will create a new ASP.NET Core MVC project in Visual Studio 2019 using .NET 5.

Copyright © 2021 IDG Communications, Inc.



Source link