Do you know what to do about ASP.NET Core default dependency injection?

Last updated by Tiago Araújo [SSW] almost 3 years ago.See history

We already know what the best IOC container is, but how does ASP.NET core's default dependency injection compare?

ASP.NET Core includes default dependency injection for new Web Apps in the Startup.cs file. This is adequate for simple projects, but not designed to compete with the features of alternatives containers (like AutoFac's convention based registration).

"The default services container provided by ASP.NET Core provides a minimal feature set and is not intended to replace other containers."

Steve Smith, (ASP.NET Dependency Injection)

You can quickly flag this error and any more by using the SSW Code Auditor.

Here is an example of rewiring the default code to AutoFac with the SSW's Music Store app:

SSW DependencyInjection Example Default Bad
Figure: Bad Example - The default dependency injection for ASP.NET Core

SSW DependencyInjection Example Default Good
Figure: Good Example - The bad example rewired to utilize AutoFac. Red boxes outline the modified code

We open source. Powered by GitHub