views:

294

answers:

3

I currently use the App_Code folder for all of my classes, and for me (for now) it seems to be working just fine.

I have however been considering making the switch over to a Class Library Project inside my Solution instead of the App_Code folder. Can anyone tell me the pros and cons of doing this?

One thought I had was with regards to testing my web app. If I use a Class Library, do I have to compile it every time I want to tweak/test? Obviously in the App_Code folder I don't have to since all of the Classes compile at runtime.

+3  A: 

You should use a class library. The reasons are simple.

You want to remove your business or application logic from the UI. The App_Code folder is only for classes that deal with the UI only.

The reason for the serpeartion is to create tiers. Meaning today you have a web site, tommrow you maybe asked to make a windows program, or a new web site. If you have to change your UI you are going to be copying and pasting the code. Which means you have now 2 or more places to maintain the code. This will lead to poorer code quality, fixing the same bug in 2 or more places.

If you place your code in a library. You create a new UI and then just reference the library. You are only now using 1 set of code.

David Basarab
This is a great answer, and one that makes perfect sense. In my question above I mentioned having to compile the Class Library over and over while testing... is there a way around this?
rockinthesixstring
So the answer is that I have to compile it every time I make a tweak or mod?
rockinthesixstring
You don't have to compile the business logic if you haven't changed it. Compiling does not take that much time and is not a good reason to keep all your code in your UI layer.
David Basarab
A: 

Jimmy Bogard (author of Automapper) has written an excellent article on how he structures his code, which may assist in confirming @David's answer.

Kane
A: 

A question to ask with regards to this discussion, previously when i was using app_code, i had a common class with a number of function that are used across different modules in my application. This common class changes quite often, at times new functions are added, but other classes that calls this class static function are never affected, as the function it calls are still there, and the only change is adding of new function to this common class in the app_code.

Recently we have moved on to new framework where every module has its own class library. again some modules do call the common-class static functions. just that now the common-class is no longer in the App_code, its a class library.

So it works, but everytime i add a new function to the common-class (class library) compile the class library and upload to (web server) bin folder, the other modules BREAKS, it complain that it cant find the function.

Solution seems to be that i cant just compile the "common-class" class library, but i have to compile all class library, then it all works with no error.

This is fine if only one person works on the solution, but if each module is done by different developer, this poses a problem.

just wondering is there a workaround? thanks all..

visual