简体   繁体   中英

Class Library Project VS App_Code - Pros / Cons?

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.

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 for classes that deal with the UI only.

The reason for the separation is to create tiers. Meaning today you have a web site, tommorow you may be 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. That 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.

吉米·鲍嘉Jimmy Bogard) (Automapper的作者)写了一篇很棒的文章 ,介绍了他如何构造代码,这可能有助于确认@David的答案。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM