Class Library Project VS App_Code - Pros / Cons? - asp.net

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 (author of Automapper) has written an excellent article on how he structures his code, which may assist in confirming #David's answer.

Related

Is there a tool that can track unused code automatically

I currently have 6 different flex applications (widgets) that run on a main page.
They all depend on one common library project.
I am currently cleaning up the codebase quite dramatically and it is hard to keep overview this way especially since I inherited the codebase.
Does anyone know a tool that can automatically inform me of any dead code?
Cheers
There are a few tools out there. I'd start with this one from Adobe; which I believe is written as an eclipse plugin.
FlexPMD is another tool; also from Adobe.
FlexCover is another.
Keep in mind that the Flex Compiler will automatically remove unused classes from your final SWF; so removing these classes from your project will probably not affect the final SWF size. I can see it helping with long-term maintenance, though..

Do you store your helper classes in a separate assembly?

I just want to know if anyone stores their helper classes or methods in a separate assembly and why...just for clean management of them? I've seen so many posts about using a helper folder inside your MVC project and that brings me back to the messy old days in ASP.NET where people were using an App_code folder instead of cleanly separating things out physically like this into its own project.
And likewise nobody doing real architecture is going to put models in some folder in your MVC web assembly. They would go in MyApp.DataLayer assembly or MyApp.Models or something like this.
Yes, but for reasons, which are common to other assemblies as well
Becomes easy to plug into any other project.(might need some editions).
Reusable
Easy to improve
Easy to refractor
As not part of a project, but project
itself, it is easy to document and easy for developers to understand
Clears out some of the mess
But for all that above, your assembly, when ready, should be a "job well done", other wise, it is better to keep the helper classes to where they belong.
We have some helpers in a separate project and some in the web project. I think you'll find that some of your helpers need to use abstractions that you've defined in your web project itself. And that will often force you to put those helpers into the web project, because it's not likely desirable to have some other project that has a reference to the web project. I don't consider it the same as using App_Code. These are files that are compiled at compile time inside your IDE, with no special "magic" that gets applied to App_Code.
I use projects to separate out the different layers in my web or form apps. It allows me to respect the business rules better. Also I find it easier to track down where I need to go if I want to make a change.
But I have seen people use folders that label the layers in the solution but I think that is a little messy.
Yes, because they are part of the Business Layer. Two big payoffs:
Reusability
Testability
Keep in mind that your utility functions and helper classes are likely to be some of the most heavily used components of your entire system. Without full BICEP testing, you run a truly unacceptable risk.
Most helpers that I create are usually layer specific so I tend to keep them with the assembly the base assembly that needs them. I don't see a reason to add in another project to store a large number of specific helper classes.

Best way to encapsulate component that includes logic and webforms

I have written a data browsing library that is being used in several projects. The library or component includes some classes as well as some ASPX pages.
Until now, we copy all the files into each project to reuse it, with the obvious drawbacks and updating nightmares. I want to encapsulate all the library into a component that the projects can use.
What's the best way to do it? I know I can create a DLL, but I think it's only for the classes, don't know how to go with the ASPXs pages.
We are using Visual Studio 2008 and Framework 2.0
Thanks in advance
This is a perfect case for custom controls.
Change the pages into user controls, and embed the new user controls back into pages that have nothing in them but the reference to the user control.
Once that works, you can change the user controls into server controls, little by little. They will be composite controls, as the user control already is.
There's a trick you can use at this stage: I'm not recalling the details this late at night, but someone else will fill those in: when ASP.NET compiles a page, it first "compiles" the markup into source code, then compiles the source code. You can get ASP.NET to not delete the temporary source files. That allows you to copy into your project code that creates precisely the same HTML as the user control did.
The difference will be - it's now your code and you can refactor it as much as you like, or even include it in a custom control library.

Any way to analyze the size of a SWF built in Flex?

I have a Flex application that seems larger than it should be. There is a lot of code in it, but not a lot of assets and it just seems large, but I'm not sure how to go about figuring out where the space is going.
I know about the –link-report option, but it only gives the sizes of externally linked library classes. I'm very interested in seeing a report of the sizes of all the classes and resources in my application and it would be a huge bonus if I could also view their dependencies. Not knowing how the code is compiled I'm not sure if this is even possible, but it seems like it should since the compiler can give me the sizes of individual classes linked from other libraries.
I did some searching around, but couldn't find anything helpful. Everything points to the optimization techniques of modularizing and externally linking libraries, which I understand and will implement, but I would really love some more detailed reports of what my compiled application looks like.
To be clear, I'm not really interested in tips on how to reduce the file size, just a report on what is used for and which classes are referencing what.
Anybody have any ideas?
CORRECTION - The link report does show all classes. My particular project in Flex Builder had several CSS files set to compile to swfs. My link report for the main app was being overwritten by these css compiles!
The link report actually contains all compiled classes and not just the ones in external libraries (at least with the Flex 4 SDK). There is an xsl available that will generate an html file of the link report so it is easier to read.
Check this post: http://blog.iconara.net/2007/02/25/visualizing-mxmlcs-link-report/
There is a command-line utility called flash.swf.tools.SwfxPrinter in swfkit.jar, which comes with Flex Builder (or the plug-in or the SDK) and which you can use to analyze information about class sizes. Joe Berkovitz wrote some good instructions on how to make use of it in his blog, and he was working on an AIR-based GUI tool that leverages it, but I'm not sure if he ever published the tool. Still, you can use his instructions to leverage the utility directly from the JAR.
I found a handy little AIR app that really helps organize the link report info.
http://www.kahunaburger.com/2008/03/08/air-link-report-visualizer/
It's old but still works very well.

How can I make a framework for quickly building similar, but different, sites?

I have the need to build lots of sites that are very similar, but not exactly the same, using ASP.NET 2.0.
I'm trying to find the best way to make generating these sites quick and easy.
The sites will be used to collect information about a user, and there will be multiple steps for each site.
The sites will all collect similar information, but some sites may require less or more information than others. Additionally, certain form fields will need to be populated from different database tables, based on the site.
I would like to use a Microsoft patterns & practices solution, but I'm not sure that there is one that fits this scenario.
My current thinking is that I will put as much business logic as possible into an external assembly and then write a custom Web user control for each step for each site. I will include these user controls in a master page's Panel control.
I don't like this solution because each site will be nearly duplicating the code for the other sites.
How can I improve upon this design?
The main obstacle is that the sites are similar, but sufficiently different.
Thanks!
Alex
you can create base classes which handle all of the common functionality and then have your site specific controls inherit from their respective base classes and then implement their specific implementations.
We face this problem all the time. What we do is to have a common library that all our sites use, and to bury shared functionality in classes or utility modules in this library. Each site can then use those objects or utility functions as is, or extend the common classes. Keep in mind that these shared classes can include all kinds of things, including code-behind for pages and user controls that you can inherit from and extend.
Deciding what goes in the app and what goes in the common library is one of the hardest things about our business, though. Put it in the common library and you lose flexibility; put it in the app and you risk having duplicate code to maintain.
If you have a fairly complex database setup, it might be worth your time to come up with a framework for specifying your db schema in XML and having your app enforce that schema and build any additional SQL infrastructure that you need based on that definition (e.g. utility views, stored procedures, etc). We did this and it resulted in a huge productivity boost.
Have you looked into Monorail (www.castleproject.org) this is an implementation of themvc pattern, similar to Ruby on rails with a few nice view engines, I prefer Nvelocity.
from castle project as well you can use n implementation of ActiveRecord that makes life real nice. if you are on that trail also have a look at coln ramsay screencasts .
To be honest all ms solutions are real fat
another great thing about the castleproject is that is totally open source so you can learn loads from their code
How about using an Application Framework like DotNetNuke or mojoportal?
They both provide flexibility and enable you to develop websites very quickly with common functionality. Leaving you to develop custom modules where the functionality you require may be different. There are also thousands of other modules that can be bought which provide excellent functionality.
However we chose to use WCSF and enhanced upon it.
All the above mentioned projects are open source and some good examples of code to learn from.
I know it may be a late answer but I hope it helps

Resources