"Class Library" or App_code - idea needed

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
I was reading this tutorial:

http://www.asp.net/learn/dataaccess/tutorial02vb.aspx?tabid=63

He has :In a real-world application, the BLL should be implemented as a separate Class Library project; however, for these tutorials we'll implement the BLL as a series of classes in our App_Code folder in order to simplify the project structure

I know we want to have a 3-tier design. At my last job, it was .net 1.1, the vendor had 3 projects in the solution and they used "Visual Basic Building Blocks/BusinessFacade/dataAccess" etc. They had 3 projects one with "common" functionality .

Question about the structure of code: in 2.0, there's App_code and that article mentions Class Library. Now, if I want to use Class Library, should this go in APP_code? Just need some general ideas about how to structure the 3 tiers..
 
If you have a class library in its own DLL you just add it as a reference to the website and it will be placed in the Bin directory.

The App_Code directory is used in the new ASP.NET compilation model. Under this model the website is compiled dynamically. When you change a code file in the App_Code directory the site will automatically get recompiled on the next page load. In .NET 1.1 the website was compiled into a static DLL (you could also do dynamic compilation if you wanted). Under the new model for 2.0 you do not even have a .csproj file, so dynamic compilation is the default. If you want, you can download an add-on from Microsoft that will allow you to have projects under 2.0.
 
hmm...this is NEW project , totally done in 2.0..

your comment makes sense but doesnt answer what i'm trying to convey...

I want to know what's a good/recommanded/how-everyone-else- does- it
structure for this new project...


So..should I have my Business Layer and Data Layer in APP_CODE? Then what about the Presentation Layer? If i have 2 Class Libraries for Business Layer and Data layer..they will go into BIN , even tho this is ASP.Net 2.0?

For example, if you have a 3-tier app, how have u structured it...what do u see in the Solution Expolerer when it comes to structure of the code?
 
Anything that is modular and has a need to be referenced from multiple projects/websites should be compiled into its own assembly. This will most likely include the classes in your business and data layers. When you reference the assembly from your website Visual Studio will automatically copy it into the Bin folder.

The only files you should have in the App_Code directory of the website are code files that are directly part of the website, which will be dynamically compiled. These files are mainly going to interact with the Page and classes in your referenced assemblies. I personally try to avoid having any type of business logic in the App_Code directory mainly because 1) it's not modular and I'll probably need to reference it from somewhere else eventually anyway and 2) it's a lot easier to unit test if it's compiled into a static assembly.
 
Well, the .aspx pages do not reside in the DLL. They are just text files that reside in the website hierarchy. If you want, their respective code files can be compiled into the DLL.
 
yeah, that was a stupid question :D

Let me ask you this: in 2.0, there's no "web application project" and seems like that's an add-on:
http://msdn2.microsoft.com/en-us/asp.net/aa336618.aspx

2.0 uses a "web site model"...correct..this is what i see when I did "file/add new website". Then when I right click on the solution and choose "add", i see "new project", "visual basic" and "class library" (and other stuff).

I also see "other porject types". In 1.1, under this ,there were "enterprise template projects". This is what the vendor at my last job used to put the "web application " under...that's how they organized it. I dont see that in 2.0.

No way to organize the "web site" in 2.0 like that? I know i'm beating this to death but my light bulb is getting brighter :)
 
That is what I mentioned earlier. They have changed the model and are trying to encourage developers to rely on dynamic compilation for websites. It has been vastly improved in .NET 2.0. Regardless, a lot of people complained about not having the ability to have a .csproj file for web apps so Microsoft released an add-on for Visual Studio 2005.

In Visual Studio 2005 you have a solution for the website. You can add other project types to that solution (class libraries, etc), which will be opened with the website.
 
I downloaded the "web application" from the Microsoft site...what I dont see is "Add/New Project/Other Pojects/Enterprise Template Projects" and then "Enterprise Template Project" as one f the options... At my last job, vendor used that template and then under it had the "web application" project....instead of having everything under the root...

I know I can add Class Libraries with my DAL and BL code under that..but how can I have all my aspx pages organized..instead of having it under the root folder? (So, have 3 project folders: BL,DAL and UI (aspx pages)?
 
You can do that by simply adding a new folder and then moving the .aspx into that folder but, remember, the folder that the .aspx is in will need to be part of the url that the client uses.
 
ah , yes...

In the "web application", I see a "My Project". I added a class library to the solution and under the class library, there's another "My project"...When I double click on the one under "web application" it jumps to the root "webappliation1"..it gives me options... This is like "properties"..

i right clicked to see if i can delete it but i cant...

seems like the "web site" model in 2005 is easier!
 
probably beating this one to death but i'm getting close to wrap my head around this :rolleyes:


On www.asp.net site, I downloaded 3 sample projects they have for free to look at the layers and code examples ...

I also downloaded "DotNetNuke". For this one, the code is structured under "Windows Application" templates ..instead of for example, "class library". Seems like it's added, then the "form" code is removed. I saw that at my last job too where "web application" template is used to structure the code...

wanted to know why someone might choose "windows application" instead of "class library" for a web application.
 
Back
Top