Well, most of the web developers today develop Enterprise Web Applications. While the challenge lies on different parameters like designing the different layers, transferring data between the different layers etc., let us examine how Visual Studio 2005 and ASP.NET 2.0 help you create Enterprise Web Applications quite easily.
Designing your Data Layer
The first step in designing your application would obviously be designing your database and I would leave that part entirely at your discretion. Once you have your database ready, say you designed a SQL Server 2005 database, the next thing that you would want to do is designing your Data Access Layer. Now we immediately jump into using different modeling tools and design nice use cases / activity diagrams, class diagrams etc., While Visual Studio 2005 Team System allows you design Class Diagrams, etc., and export them for documentation, I again leave this part if you are using an external design tool. In most of the application scenarios, I have found Visual Studio and Visio mostly sufficient.
Designing the Data Access Layer using Visual Studio 2005 - Data Set Template
Start Visual Studio 2005 - Select File - New Website and chose a location and specify a name for your website, say EntWebApp.
This would create a basic ASP.NET Website with a Default.aspx page, Web.Config file etc., The next thing to do is to select - Add - New Item - DataSet and provide a name say CustomersDAL.
It would prompt you to save the file in the App_Code folder. The App_Code folder is new in ASP.NET 2.0 which allows you to place class files which are compiled dynamically at run time as well as be accessible across the application.
Once you click "yes", it creates a CustomerDAL.xsd file with a visual interface to design the Data Access Layer. Using Server Explorer (View - Server Explorer), connect to the Database server node and navigate to your particular database say "NorthWind" Database.
There after, you can drag and drop the tables and start configuring them. The Data Set designer provides you all the relational information as well as exposes the Table fields as properties for each Table embedded into a Table Adapter.
Say you designed your Customers Table as CustomersDALTableAdapter. It prompts you to configure your connection string and you can configure the connection string that can be stored in the web.config file. Once you complete this step, you can chose the table and also specify the columns to be returned. You could do this in different ways. You can either chose SQL queries, or Create New / Use Existing Stored Procedures in the Database. Once you do that, you have your first DataAccess Method (Query) ready. You can add multiple methods to it by clicking on "Add Query" and configure as many retrieval jobs you would want to accomplish. You could also drag and drop more tables from the server explorer and configure them.
Designing your Business Class Methods (Middle Tier Components)
Once we are done with our Data Access Layer, we need to start designign your middle tier components. We have different approaches today in designing our middle tier components. We create a Business Layer and probably a Business Facade layer or simply go with a Business Layer. In this case, we will have a Business Layer which is designed as a C# class file. We could also use VB.NET to accomplish this, as well as use a Class Library Project to add more business methods. But for the sake of simplicity I am going to have one class file.
Right Click the Website root, select - Add New Item - select Class template and create a CustomersBL.cs file. Note that this file would act as our business layer.
So far, we haven't written any line of code and so pretty much easy. In this business layer, we want to write a couple of methods which would help in a. implementing our business logic if any and use the CustomersDAL that we created using Table Adapter Configuration Wizard.
In the CustomersBL.cs file, we would write the following code snippet
public DataTable GetCustomers()
{
CustomersDALTableAdapters.CustomersTableAdapter customersDB =
new CustomersDALTableAdapters.CustomersTableAdapter();
// Implement any business logic here
return customersDB.GetData();
}
public DataTable GetCustomerByCustomerID(string customerID)
{
CustomersDALTableAdapters.CustomersTableAdapter customersDB =
new CustomersDALTableAdapters.CustomersTableAdapter();
// Implement any business logic here
return customersDB.GetDataBy(customerID);
}
Note that I have left the commented portion for any business logic you would want to implement. If we examine the above code snippet, we could figure out that we have programmatic access to the Table Adapter we created and it provides you the typed flexibility to call methods defined in your DAL Layer.
Once we are done with the above, we just need to build the website once to check for any errors / issues.
Designing your UI Layer
Now we come to the part of designing the UI Layer. We already have the Default.aspx page which is created when we created the website. We could use the same page or add a new webform as appropriate and then add a GridView control from Toolbox - Data section. Switch to Design mode if you are in source view. This allows you to configure the GridView's databinding properties.
Once you hover over the GridView in design mode, you get the smart tag option to chose and configure the GridView properties. Select "Chose Data Source' - "New DataSource" and in the prompted list, select "ObjectDataSource". The next UI would provide you with a list of Business Objects and a checkbox named "Show only Data Components". Uncheck the checkbox so that it also shows the Business Layer Class we created.
You can select the CustomersBL that we created and the next screen allows you to "Choose your Method". Select the GetCustomers that we had written in the Business Layer. Once you click "Finish" you can format the GridView by selecting the Auto Format and selecting a scheme. Also you could enable Paging, Sorting and Selection from the same wizard. With that we are good to run the page and once you run the page you would be able to find that the Customers Records are displayed in a paged manner.
Next you would want to link the GridView to a Details View control to have a master-detailed view of the records. To do that add a new Details View control to the page. Configure it to use a new Object DataSource and repeat the steps as we did for the GridView, except that in the "Choose your method" screen you must choose GetCustomerByCustomerID since we would try to retrive a particular Customer Record.
You would be prompted with an additional screen to chose the input parameter settings since this method requires an input parameter. You can chose the parameter source and in our case it is "Control" and the ControlID is "GridView1". Also we need to specify a default value 0.
We need to do one additional step. Select GridView properties and specify "CustomerID" in the DataKeyNames property for the GridView.
When we run the page, we initially see only the GridView neatly paged and showing the first set of records. Upon clicking on "Select" we would be able to see the DetailsView of the selected record. (In case you don't see the "Select" option, you might have missed "Enable Selection" in the GridView configuration)
This page now provides a kind of Master-Detailed View of the Customers Record and it retrieves data from Database using TableAdapter, Business Layer and Object DataSource which makes it a three tier architecture and thereby an Enterprise Web Application Architecture.
Cheers !!!