Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Build 'Radioactive' Web Sites with DotNetNuke 2.0 : Page 4

Save hours of valuable development time when building corporate or departmental Web portals with DotNetNuke 2.0, the latest version of the free, ASP.NET-based, open source, extensible, content management portal.

Data Access
While the new skin features might be the most important new feature for site administrators and site designers, to developers responsible for coding custom modules, one of the most significant issues with DNN 2.0 is the new data access methodology. The DNN core team has implemented the Whidbey (ASP.NET 2.0) Provider model for data access. Adopting this methodology enables DNN to integrate with any data store. DNN 2.0 ships with a Microsoft SQL Server/MSDE data provider and a Microsoft Access data provider. DNN 2.0 includes significant revisions to the web.config file. The most obvious of these changes is the addition of the Providers collection to support additional databases (see Listing 1).

The data model in DNN 2.0 takes an n-tiered or layered approach to working with data. If upgrading to DNN 2.0 is going to be your initial introduction to the world of layered data access, be prepared to spend some time absorbing and learning. Your maiden voyage into the uncharted waters of a multi-tiered or layered approach to working with data can be as unsettling as being on a ship in rough. The good news is that it does not have to be that upsetting. There are four fundamental layers in a typical multi-tiered application: the Presentation layer, the Business Logic layer, the Data Access layer, and the Data Store layer. If you have ever taken a standardized test such as the S.A.T. exam, for example, then you have a perfect frame of reference for understanding how a layered approach to application development works. I will explain each layer and break down the layers in the standardized test taking process to help you associate application layers with your real world experience. Later in the article I will demonstrate how to implement the layers in .NET code.

I will start with the layer closest to the user, the Presentation layer, and work my way back toward the database. The Presentation Layer
The Presentation layer displays information to the user and provides a mechanism for them to enter or update information. A Windows Form implements this layer in a traditional Windows application and a Web Form (ASP.NET) implements this layer in a Web-based application. I often refer to this layer as the "make the data look pretty" layer. Limited data validation occurs at this layer.

Your maiden voyage into the uncharted waters of a multi-tiered or layered approach to working with data can be as unsettling as being on a ship in rough seas. The good news is that it does not have to be that way.
In the example of a standardized exam, the exam itself represents the Presentation layer, though recalling my experiences with standardized exams; the results were rarely "pretty." Data is collected when an individual taking the exam records their answers on the separate exam answer form. That seems simple enough. No real rocket science here. The Business Logic Layer
The Business Logic layer (BLL) acts as a conduit between the Presentation layer and the Data Access layer. It is responsible for validating the data passed to it by the Presentation layer before it sends the data along to the Data Access layer. The BLL also retrieves data from the Data Access layer and passes it to the Presentation layer. Typically, a developer creates a Custom Business Object (CBO) (CBO is DNN's name for a Business Logic layer object) for each table in the database. For example, the CustomerBusinessObject works with data from the Customer table.

The CustomerBusinessObject would handle data validation chores such as ensuring that the customer's first name and last name are not blank. The code in a CBO is highly customized to fit the requirements of the table it is representing. Back to the standardized exam example. The exam administrator sitting in front of the classroom who monitors the students during the exam represents the Business Logic layer. A student turning in their completed exam answer form is an example of the Presentation layer passing data to the Business Logic layer. Validation steps the exam administrator might take include verifying the exam was completed in the allotted time, that the student's name is on the exam, and that the student used a #2 pencil. Did you notice that I didn't mention anything about scoring the exam or determining if any or all of the questions had been answered? In this case, scoring is not the responsibility of the exam administrator. Once the exam has passed the validation rules implemented by the exam administrator, the test is sent to a testing company for scoring.

Does the exam administrator care what type of database contains the exam results or how the exam results get recorded? No. That is not their responsibility. Handing out the answer forms, applying a few validation rules to exams handed in, and sending the exam answer form to be scored is the entirety of their job. The Data Access Layer
The Data Access layer (DAL) accepts the pre-validated data coming from the Business Logic layer and calls the correct data updating capability on the Data Store layer. DAL objects are designed and coded for a particular data store to take advantage of specific capabilities and features of the data store including performance and security.

In my standardized exam example, the testing company who receives the pre-validated exam answer form from the exam administrator represents the Data Access layer. Getting the results entered into their system and scoring the exam is their responsibility. The Data Store Layer
The Data Store layer (DSL) represents the data storage entity itself. For this article, Microsoft SQL Server 2000 is the DSL.

In the standardized test example, the DSL is represented by the database (tables, stored procedures, and so on) that the company stores the exam scores in. Using stored procedures to access and update data is an accepted "best practice" and DNN uses stored procedures exclusively to work with data. Layered Architecture Advantages
Flexibility is one of the primary advantages of a layered architecture. In the standardized exam example, does it really matter who the exam administrator is? No, so long as they can carry out the duties and responsibilities expected of an exam administrator. Does the exam administrator know what database the standardized exam company uses? No, they do not need to know. Does it really matter what database the exam company uses to store test results? No, as long as they can score the exams and distribute the results to exam takers. Are all of the layers independent of each other? No, they aren't. Keep in mind that the Data Access layer is coded to work with a specific Data Store layer. If someone decides to swap out the Data Store layer (switch from Oracle to SQL Server for example) someone might have to recode the Data Access layer to take advantage of SQL Server features and capabilities. Would swapping the database have any impact on the exam administrator or change the rules they implement? No. Would the change affect the student taking the exam? No.

A clear and manageable division of human labor is another advantage of a layered architecture. Because you can develop each layer independently of the others, individual team members can handle specific tasks. A graphic artistic can collaborate with a Web designer on the visual aspects of the application (Presentation layer) while developers work on the custom business objects (Business Logic layer). Meanwhile, another team of developers can collaborate with the DBA on the data access objects (Data Access layer). Lastly, a DBA can implement the table schemas and code the stored procedures in the database. Layered Architecture Disadvantages
The layered approached to accessing data obviously has advantages but it also has disadvantages. The most significant is the level of complexity and potential confusion that comes with having several layers. Because each table has its own Data Access layer object and Custom Business Object, the number of classes can grow very quickly.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date