.NET Pet Shop


If you have been a Java 2 Enterprise Edition (J2EE) developer, Java Pet Store should sound very familiar. As the name suggests, Java Pet Store represents an online store for buying pets (dogs, fish, and the like). Behind the scenes, Java Pet Store essentially is a blueprint application that was authored to demonstrate how various J2EE technologies ”particularly Enterprise Java Beans (EJB), Servlets, and Java Server Pages (JSP) ”can be utilized in a cohesive fashion to build an online electronic commerce application. A key aspect of the Java Pet Store application is that is has been used by Sun to highlight a set of design patterns that can be used in real-world applications. In essence, the Pet Store application is really a "Hello World" to the J2EE platform. (Of course, it does much more than echo "Hello World" to the console.)

SHOP TALK : MICROSOFT .NET AND J2EE

Microsoft .NET and J2EE are clearly emerging as the two major platforms for application development. In a number of real-world application scenarios, you will be asked to make a decision between the two. Both platforms have similar technologies and also have their unique distinctions. It is important to understand the pros and cons of each of the platforms to make an informed decision. For instance, Microsoft .NET provides the flexibility to program in multiple programming languages, providing you the benefit of leveraging skills in those areas. On the other hand, J2EE requires Java to be exclusively used as the programming language. Even though there are initiatives to make the .NET Framework available on other platforms (as highlighted in the last chapter of the book), Microsoft .NET is primarily available on the Windows platform. On the other hand, J2EE enjoys platform independence, and it would make sense to consider it if your organization has a lot of investments in Unix OS hardware.


The .NET Pet Shop application was developed by Microsoft to compare and contrast application development between the two platforms: J2EE and .NET. Another key objective was to benchmark performance of .NET applications versus similar J2EE applications. In fact, .NET Pet Shop version 3.0 is the application that has been submitted to The Middleware Company (http://www.middleware-company.com) for comparing performance metrics of the .NET platform with leading J2EE application server vendors .

Requirements

The functionality of the .NET Pet Shop has been derived from the original Java Pet Store. It looks and feels very similar to its predecessor. It is a very basic Amazon-like electronic commerce application that allows users to browse and search a catalog of pets, add them to their shopping cart, and check and submit orders using credit card information. Note that .NET Pet Shop doesn't implement the back-end administration and mailer functionality of Java Pet Store.

Figure 15.1. Original Java Pet Store.

Figure 15.2. .NET Pet Shop.

Key application requirements for .NET Pet Shop are the following:

  • Sign in using existing profile ( user verification)

  • Create new profile

  • Update existing profile

  • Browse catalog

  • Search catalog

  • Add products to shopping carts

  • Update quantities in shopping carts

  • Checkout using credit card information

  • Checkout confirmation

In addition to the preceding online capabilities, the .NET Pet Shop also provides a basic Web service to inquire about order information for a particular order number.

Apart from the preceding application- related requirements, a number of technical requirements have also been put together as the basis for .NET Pet Shop. Key requirements are the following:

  • Browser-based application delivery model (no thick clients !)

  • Support for parts of the application to be protected (using traditional user/password authentication mechanism)

  • Support for multiple databases (in particular, Microsoft SQL Server 2000 and Oracle 9i)

  • Distributed transactions (The orders database can be different from the item catalog database.)

  • High performance

  • Scalability, including support for load balancing and failover

  • Ease of application maintenance

Application Design

The .NET Pet Shop has been designed using the following technologies of the .NET platform:

  • Programming language: Visual C#

  • ASP.NET for user interface, Web pages, and controls

  • .NET managed components for the business logic and data access components

  • ADO.NET and database-specific providers for data access

  • .NET Web services for order information Web service

Figure 15.3. .NET Pet Shop application design.

A key highlight of the .NET Pet Shop is the abstraction of the data access layer (commonly abbreviated as DAL) components. Even though .NET allows abstracted data access to multiple data sources using a generic OLE DB provider, database-specific managed providers are typically used to get the best performance required for the application. However, the logic to access databases was kept hidden from the higher level business logic layer (BLL) components using a well-defined interface abstraction.

PORTABILITY, PERFORMANCE, AND MAINTENANCE

Application performance and portability always go hand in hand. If you focus on one, the other gets compromised. A key criterion of the overall performance of any application is based on how fast the application can access the underlying databases. Although generic "drivers" are always available, the best performance is typically achieved by database-specific providers. This does impact maintenance because now you have to port some components of the application if you ever move to another database. Databases are typically standard technologies in an organization and such requirements may be less in a typical enterprise scenario. However, if you are an Independent Software Vendor and potentially see your application installed and configured for different customers, you need to be prepared to run your application in a number of scenarios. So when you consider database access, consider performance and portability requirements in the beginning so that you can be prepared for the appropriate development and maintenance requirements.


The database design for the .NET Pet Shop was adopted from the original Java Pet Store. The Sybase Schema for Java Pet Store was incorporated as the SQL Server database schema, and the original Oracle schema was used for Oracle support. Following is a brief overview of the various tables used in the .NET Pet Shop application.

User profile related tables:

  • Account Basic user information such as UserId, Email, First/Last Name, Address, and so on

  • Profile User-specific preferences, such as language and favorite category

  • SignOn User ID/password combination

Banner related:

  • BannerData Ad banner information

Catalog related:

  • Category Overall catalog categories (fish, dogs)

  • Product Catalog products

  • Item Variants of Products (for example, Spotted/Spotless fish), which represents a traditional SKU

  • Inventory Product inventory

  • Supplier Supplied information

Order related:

  • Orders Orders placed in the system

  • LineItem Line item “level details for orders placed

  • OrderStatus Current order status

The Orders information is separated from the User/Catalog information. This tries to replicate a separate fulfillment system, which is typically the case in a real-world scenario.

Components of the Pet Shop Application

Visual Studio .NET Solution and Projects was utilized by developers of .NET Pet Shop to organize and separate the various tasks of building such a solution. As highlighted earlier, by using Solutions and Projects, the overall solution can be divided into a set of manageable subsets. These subsets can then be tasked to individual teams for concurrent development. If you are planning to extensively utilize the Visual Studio .NET environment, you should also consider storing the source code in a Source Code Management (SCM) repository such as Visual SourceSafe. This way, individual team members can update their own deliverables without accidentally changing their colleague's code.

Figure 15.4. .NET Pet Shop database design (reverse engineered using Visio).

Returning to the .NET Pet Shop, the overall solution was divided into the following projects:

  • BLL Business logic components for Account, Cart, Inventory, Item, OrderInsert, OrderRead, Product, and Profile. In particular, OrderInsert supports distributed transactions by using System.EnterpriseServices attributes.

     
     [Transaction(System.EnterpriseServices.TransactionOption.Required)] public class OrderInsert : ServicedComponent { 
  • ConfigTool Used by the installation program to configure Event Log and encrypt database connection settings.

    Figure 15.5. .NET Pet Shop Visual Studio .NET solution.

  • DALFactory Provides the necessary abstraction to utilize a specific DAL implementation. For instance, examine the code snippet for Account Factory class.

     
    [View full width]
     
    [View full width]
    namespace PetShop.DALFactory { public class Account { public static PetShop.IDAL.IAccount Create() { string path = System.Configuration.ConfigurationSettings. AppSettings["WebDAL"]; string className = path + ".Account"; return (PetShop.IDAL.IAccount) Assembly.Load(path). CreateInstance (className); } } }

    The WebDAL parameter is specified in the web.config file:

     
     <?xml version="1.0" encoding="utf-8"?> <configuration>   <appSettings>            ...     <add key="WebDAL" value="PetShop.SQLServerDAL" />     <add key="OrdersDAL" value="PetShop.SQLServerDAL" />   </appSettings>   ... </configuration> 
  • IDAL Interfaces for DAL objects; for instance, following is the interface for Account:

     
     namespace PetShop.IDAL {         public interface IAccount         {                 AccountInfo SignIn(string userId, string password);                 AddressInfo GetAddress(string userId);                 void Insert(AccountInfo account);                 void Update(AccountInfo Account);         } } 
  • Model Serializable containers for various business entities. These classes contain a list of read-only properties that hold data in transit (between method calls).

     
     namespace PetShop.Model {         [Serializable]         public class AccountInfo {                 private string _userId;                 ...                 public AccountInfo(string userId, ...}                         this._userId = userId;                         ...                 } ...                 // Properties                 public string UserId {                         get { return _userId; }                 } } 
  • OracleDAL Oracle-specific implementation of DAL components. Uses Oracle Data Provider classes from the System.Data.OracleClient namespace.

  • SQLServerDAL SQL Server-specific implementation of DAL components. Uses SQL Server Data Provider classes from the System.Data.SqlClient namespace.

  • Utility Utility classes to encrypt and decrypt information such as connection strings.

  • Web ASP.NET Web pages and controls (AddressUI, Cart, Navigation Bars, Preferences, and so on). In addition, this project contains two classes, AccountController and CartController, which control the navigation structure for account- and cart-related events. The Web project also contains the simple Order Info Web service as well. The ASP.NET configuration file is used to secure part of the Web application (EditAccount.aspx, OrderBilling.aspx, OrderShipping.aspx, OrderProcess.aspx, MyAccount.aspx) by an appropriate directive in the web.config file. Web forms-based authentication is also enabled.

     
     <?xml version="1.0" encoding="utf-8"?> <configuration>   <system.web>     <authentication mode="Forms">       <forms name="PetShopAuth" loginUrl="SignIn.aspx"        protection="None" timeout="60" />     </authentication>     ...   </system.web>   <location path="EditAccount.aspx">     <system.web>       <authorization>         <deny users="?" />       </authorization>     </system.web>   </location>   ... </configuration> 
  • Post-Build, Pre-Build Projects used in add/remove actions such as GAC assemblies and COM+ initializations.

Installation and Setup

.NET Pet Shop is available as a single Windows Installer file (PetShop 3.0 Installer.msi, 771KB) from Microsoft's MSDN Site, http://msdn.microsoft.com/library/en-us/dnbda/html/bdasamppet3.asp. Before you install and configure .NET Pet Shop on your machine, make sure that you understand the system requirements for the application, summarized next :

  • .NET Framework ” 1.0/1.1. (Version 1.1 of the framework is required for Oracle Implementation).

  • Operating System/Web Server ” Windows 2000 or Windows 2003. (I used Windows 2003.) In addition, Internet Information Services (IIS) needs to be configured. If you are planning to run .NET Pet Shop on Windows 2000, please read the Readme document that comes along with the installation because you might need to perform extra steps.

  • Database ” SQL Server 2000 or Oracle 9i. (If you are planning to use Oracle, you will need appropriate Oracle client software as well).

  • Visual Studio .NET ” Visual Studio .NET 2002/2003; although it is not required, it is helpful to browse through the various projects, builds, and so on. A missing piece of the .NET Pet Shop is a command-line “based build script.

Administrative privileges on the machine are required for installation and configuration.

The installation program creates shortcuts for the Visual Studio .NET Solution file for .NET Pet Shop as well. (Select Programs, Microsoft .NET Pet Shop 3.0, PetShop.sln.)

Design Techniques Illustrated

As you can see, the .NET Pet Shop is a relatively straightforward application. However, the simplicity of the application is probably its strength because it illustrates a number of design techniques:

  • Database independent, data access layer using database-specific data providers ” The abstraction of the data access layer components (Factory, Interfaces, and the like) is the main design pattern highlighted and the biggest takeaway from the .NET Pet Shop application.

  • Model View Controller (MVC) architecture ” The application utilizes Model (AccountInfo), View (ASP.NET Page/Control), and Controller (AccountController) architecture. MVC design pattern, a popular design pattern in GUI-related application development separates the various components ”logic, presentation, and event model of the application. The pattern promotes reusability and ease of maintenance. However, as the .NET Pet Shop illustrates, it is also important to realize that ASP.NET's code-behind model overall approach is quite similar to the explicit MVC design pattern.

  • Caching ” Caching and performance go hand in hand. In an electronic commerce application such as .NET Pet Shop, data related to the product catalog is the most appropriate information that can be cached (either based on time intervals or based on an explicit callback). Actually, because of the explicit "No Page Level Caching" rule that has been established as a rule for the benchmark, the .NET Pet Shop uses a limited set of caching capabilities that is provided by the platform.

  • Database-specific managed providers for high performance ” .NET Pet Shop illustrates the fact that best performance of the system is typically achieved by using a database-specific managed provider. Managed providers are now available for a number of popular relational databases, including Microsoft SQL Server, Oracle, and IBM DB2.

  • Distributed transactions ” .NET Pet Shop applications use separate databases to store product catalog data, user profiles, and orders data. These can be either separate instances or altogether separate database systems (Oracle/SQL Server). This requires the application to support distributed transactions; fortunately, the .NET framework alleviates the need for the developer to explicitly code for multiple databases by providing the Distributed Transaction Coordinator (DTC) Services by setting an appropriate attribute.

  • Solution organization ” If you revisit the Visual Studio .NET solution for .NET Pet Shop, the various components of the solution are kept separately, promoting concurrent development with well-defined interfaces. A takeaway from this is to organize your application into Data Access Layer, Business Logic Layer, DAL Implementations (if required), Web application, Utilities, and general setup components.

Real-World Applications

.NET Pet Shop is good sample application to understand how different .NET technologies work together. Because it has been used as the baseline for benchmarking, you can use different physical implementations of the application to understand how a particular architecture could scale. For instance, what would happen if you increased CPUs, memory, or added another server into the Web farm, or what would happen if the Web server and database server were on the same or different machines? Of course, the .NET Pet Shop application can be used to understand the differences and similarities between .NET and J2EE platforms.

Apart from system benchmarking, .NET Pet Shop can be a good template for a simple electronic commerce-style application. A couple components can be utilized or extended as well. Even if your application isn't related to electronic commerce, the data access layer abstraction components can be very helpful (almost all applications need to access back-end data). The encryption and decryption components for database connection strings can also be utilized.



Microsoft.Net Kick Start
Microsoft .NET Kick Start
ISBN: 0672325748
EAN: 2147483647
Year: 2003
Pages: 195
Authors: Hitesh Seth

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net