May 26, 2014 04:28 PM|ploeh|LINK
It looks like one of the proposed new features of the next version of ASP.NET is a library or API simply titled Dependency Injection. In this post, I will provide feedback to the team on that particular
sub-project, in the form of an open blog post. The contents of this post
was originally posted on my blog.
Dependency Injection support
The details on the motivation for the Dependency Injection library are sparse, but I assume that the purpose is provide 'Dependency Injection support' to ASP.NET. If so, that motivation is laudable, because Dependency
Injection (DI) is the proper way to write loosely coupled code when using Object-Oriented Design.
Some parts of the ASP.NET family already have DI support; personally, I'm most familiar with ASP.NET MVC and ASP.NET Web API. Other parts have proven rather hostile towards DI - most notably ASP.NET Web Forms. The problem with Web Forms is that Constructor
Injection is impossible, because the Web Forms framework doesn't provide a hook for creating new Page objects.
As far as I can tell, the current ASP.NET Dependency Injection code defines an interface for creating objects:
public interface ITypeActivator
params object parameters);
In addition to this central interface, there are other interfaces that enable you to configure a 'service collection', and then there are Adapters for
As far as I can tell, there's no web code in the ASP.NET Dependency Injection code base. In other words, this is a poster example of a Conforming
It's an excellent idea to add 'Dependency Injection support' to ASP.NET, for the few places where it's not already present. However, as I've previously explained, a Conforming Container isn't the right solution. The right solution is to put
the necessary extensibility points into the framework:
In addition to adding these required extensibility points, I recommend completely abandoning the project of defining a Conforming Container. The extensibility points should be added where they're used - the MVC Factories as part of MVC, the Web
Form Factories as part of Web Forms, etc. This will have the added benefit of making the ASP.NET Dependency Injection project redundant. Less code is better than more code.
"perfection is attained not when there is nothing more to add, but when there is nothing more to remove." - Antoine de Saint Exupéry
These are my general recommendations to the team, but if desired, I'd also like to offer my assistance with any particular issues the team might encounter.