App_Code: Why it’s Better
I remember when ASP.NET 2.0 beta 1 was released about 2 years ago and I eagerly tried it out.
The first thing that struck me as strange was the new application folders like App_Code, App_Data, and App_Themes etc. They all made perfect sense except App_Code.
I didn’t see the point of putting code in the folder because a separate assembly is a much cleaner approach.
After some weeks I finally got the point. It had nothing to do with putting code-behind files in it to make them globally accessible because that is just bad architecture.
No, it was much more important than that. It was about componentizing ones application to an even smaller degree than by using and reusing separate assemblies.
The App_Code folder allows me to use HttpModules, handlers, classes and other code pieces that don’t naturally belong together in a separate assembly.
By now a have a pretty decent collection of code that I use for various different ASP.NET applications and I can simply pick just the ones I need and drop them into the App_Code folder.
That means that it is no longer necessary to reference a separate assembly and only use a couple of its classes.
That makes the application easier to debug and you know exactly what code pieces you use at all times – just look in App_Code.
In ASP.NET 1.x none of this has any meaning because all classes can be made globally accessible without moving them to some special location.
But in ASP.NET 2.0 this is a great way of abstracting components from the rest of the code.
That’s why App_Code is better.
The only thing you have to do in order to get the full advantage is to start collecting reusable components.
Mads Kristensen currently works as a Senior Developer at Traceworks located
in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in
2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and
web services in his daily work as well. A true .NET developer with great passion for the simple solution.