Justin Obney
Justin Obney

Reputation: 1078

Separating Web Applications into multiple projects

I have a web application that is becoming rather large. I want to separate it into smaller more logical projects, but the smaller projects are still going to need to access some of the classes in the app_code of the main project. What are some good methods to accomplish this?

Upvotes: 2

Views: 2031

Answers (7)

Even Mien
Even Mien

Reputation: 45858

If you are only looking for a way to organize your files, then you can create a folder for each sub-project. This way you'll be able to get to the content of app_code and maintain a level of separation with very little rework.

If you are looking for the best way to do this, then refactoring your code to have a common Class Library based on what is reusable in the app_code folder and multiple, separate projects that reference that library is the way to go.

You may run into problem refactoring the code this way, including not being able to reference profile or user information directly. You are now going from the Web Site to Web Application paradigm.

http://www.codersbarn.com/post/2008/06/ASPNET-Web-Site-versus-Web-Application-Project.aspx

Upvotes: 2

Korbin
Korbin

Reputation: 1808

A somewhat simple approach is to group the code in your app_code folder into it's own assembly. The only issue that you could possibly run into is if the code in your app_code folder is not decoupled from the elements on you pages (This is normally always a bad idea since it indicates poor cohesion in you classes).

Once you have your code in a separate assembly you can deploy it to any number of servers when you are upgrading you apps.

Upvotes: 0

mike
mike

Reputation: 5213

Here's an example of what I'm doing within my projects.
The basic idea is to have all common files separately from htdocs so they are not accessible by client directly and sharable.

Directory structure:
public_html
The only htdocs dir for all projects.
Stores only files which should be directly accessible by client, ie js, css, images, index script

core
Core classes/functions required by application and other scripts. Framework in other words.

application
Stores files used to generate separate pages requested by public_html/index script + classes common to all projects

config
Configuration for all projects, separated by project

templates
Template files separated from all other files


The public_html/index script is then used for all projects on all domains/subdomains and based on the requested URL loads proper pages...

Upvotes: 0

Rob Allen
Rob Allen

Reputation: 17709

I like the 3 Tier approach of creating a data access project, a separate business project, then use your existing site code as the presentation layer, all within the same solution file.

You do this, like posters before me said, by creating Class Library projects within your existing solution and moving your App_Code classes to the appropriate layer and then referencing the data access project in the business project, and the business project in the web project.

It will take a bit of time to move it all around and get the bits and pieces reconnected once you move so make sure you set aside plenty of time for testing and refactoring.

Upvotes: 1

lo_fye
lo_fye

Reputation: 6840

In CVS & Subversion, you can setup what I think are referred to as "aliases" (or maybe it's "modules"). Anyway, you can use them to checkout part(s) of your source control tree. For example, you could create an alias called "views" that checks out all your HTML, javascript, and css, but none of your php/java/.NET.

Upvotes: 0

Joseph Daigle
Joseph Daigle

Reputation: 48428

Extract your common code from app_code into a class library which is referenced by each of your other projects.

Upvotes: 2

Paul van Brenk
Paul van Brenk

Reputation: 7549

Add a class library project with the common classes and add a reference to this project to each of the new projects.

So you'll have the following Solution layout

/webapp1
   /default.aspx
   /....
/webapp2
   /default.aspx
   /....
/lib
   /Utils.cs

Upvotes: 6

Related Questions