Why App_Code is better

Dec 5, 2006

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.

* $4.95/month BlogEngine.net Hosting – Click Here!

Comments (1) -

 Sean
Sean
12/8/2006 5:12:06 PM #

Personally I don't really feel that App_Code gives me any advantage over assemblies in terms of debugging.  I can tell which pieces are used just by reflection or by checking references.  Like you, I used App_Code for a while, and I still do in many cases, but in general I've moved back to separate assemblies (one for handlers, one for utilities etc.)  The kicker for me was that as I made modifications and updates to my various pieces of code I got tired of dropping them in to several different App_Code folders.

Comments are closed

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.