FeaturedIT topics

How to use Scrutor in ASP.Net Core

Dependency injection (DI) facilitates loose coupling and promotes testability and maintenance. You can take advantage of dependency injection to change your implementations without having to change the classes or interfaces that leverage those implementations. Dependency injection is one of the SOLID principles of software architecture. It is used to decouple the usage of an object from the way the object is constructed.

Without dependency injection, an object has to be modified if any of its dependent objects change. If dependency injection wasn’t available, it would be very difficult to unit test objects that have dependent objects. With dependency injection, an object doesn’t construct its dependent objects internally; rather, dependent objects are injected at runtime.

Dependency injection is a first-class citizen in ASP.Net Core. However, by design, ASP.Net Core includes only a simple DI container with minimal capabilities, leaving it to third parties to extend those capabilities. Scrutor is an open source library that adds assembly scanning capabilities to the ASP.Net Core DI container. This article examines how we can work with Scrutor in ASP.Net Core.

It’s important to note that Scrutor is not a DI container. Rather, Scrutor provides a fluent API to register services based on conventions, using the built-in DI container of ASP.Net Core. If you need a DI container with more features and capabilities, you can use third-party DI containers such as AutoFac, Windsor, StructureMap, Ninject, and DryIoc. Scrutor can be used to provide assembly scanning and decoration extensions in ASP.Net Core. 

Create an ASP.Net Core Web API project

Related Articles

Back to top button