Do you know what to do about ASP.NET Core default dependency injection?
  v2.0 Posted at 30/07/2019 11:24 AM by Tiago Araujo

​​We already know what the best IOC containe​r 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:

Figure: Bad Example - ​​The default dependency injection for ASP.NET Core
​​Figure: Good Example - The bad example rewired to utilize​ AutoFac. Red boxes outline the modified code

Further Reading:​

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address: