Home
Do you know what to do about ASP.NET core (aka ASP.NET 5) default dependency injection?
  v1.0 Posted at 11/02/2016 4:28 PM by Andrew Lean

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

ASP.NET 5 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 5 provides a minimal feature set and is not intended to replace other containers.​​" - Steve Smith, (ASP.NET Dependency Injection )


You can quckly 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.png ​​​​
Figure: Bad Example - ​​The default dependency injection for ASP.NET 5​
​​SSW-DependencyInjection-Example-Default-Good.png
​​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:

    Comments:

    Note: Social Media login for Yotpo is not working in IE or Safari, please use Chrome. We are waiting for Yotpo to fix it.