MVC 4 and the App_Start folder
I've been delving into ASP.NET MVC 4 a little since its release last month. One thing I was chomping at the bit to explore was its bundling and minification functionality, for which I'd previously used Cassette, and been fairly happy with it. MVC 4's functionality seems very similar to Cassette's; the latter's CassetteConfiguration class matches the former's BundleConfig class, specified in a new directory called App_Start.
At first glance, this seems like another special ASP.NET
folder, like App_Data, App_GlobalResources,
App_LocalResources, and App_Browsers. But Visual Studio
2010's lack of knowledge about it (no Solution Explorer
option to add the folder, nor a fancy icon for it) made me
suspicious. I found the MVC 4 project template has five
classes there--AuthConfig, BundleConfig, FilterConfig,
RouteConfig, and WebApiConfig. Each of these is called
explicitly in Global.asax's Application_Start method. Why
create separate classes, each with a single static method?
Maybe they anticipate a lot more code being added there for
large applications, but for small ones, it seems like
overkill. (And they seem hastily implemented--some declared
as static and some not, in the base namespace instead of an
App_Start/AppStart one.) Even for a large application I work
on with a substantial amount of code in Global.asax.cs, a
RouteConfig might be warranted, but the other classes would
remain tiny.
More importantly, it appears App_Start has no special magic
like the other folders--it's just convention. I found it
first
described in the MVC 3 timeframe by Microsoft architect
David Ebbo, for the benefit of NuGet and WebActivator; apparently some packages will add their own classes to
that directory as well. One of the first appears to be
Ninject, as most mentions of that folder mention it, and
there's not much information elsewhere about this new
folder.