Click here to Skip to main content
15,867,686 members
Articles / Desktop Programming / WPF

Northwind N-Tier Blueprint Application Using WPF/WCF/LINQ to SQL

Rate me:
Please Sign up or sign in to vote.
4.41/5 (17 votes)
5 Feb 2014CPOL4 min read 56.2K   2.4K   59   17
A blueprint application to showcase an enterprise standard architecture using the .NET 3.5 technologies like WPF, WCF, and LINQ to SQL.

Introduction

Northwind N-Tier Blueprint is a Windows client application that can be used to manage the customers and their details of a fictitious company called Northwind Traders. This application is developed as a blueprint to showcase an enterprise standard architecture using the .NET 3.5 technologies like WPF, WCF, and LINQ to SQL. This can be used as a reference for building reliable applications with a service oriented and distributed architecture.

Application Features

As this is a blueprint application, the functionality is limited to just what is required for demonstrating typical operation units in an application. When the application is launched, the main window opens with a set of buttons. Clicking on the ‘Load’ button will load all the customers from the database.

NorthwindNTierBlueprint/applicationscreen.jpg

A new customer can be added by clicking on the ‘New’ button which opens up a pop-up window for adding the details of the customer. A selected customer can be edited by clicking the ‘Edit’ button, or can be deleted by clicking the ‘Delete’ button. The ‘Edit’ button opens up the pop-up window, loading the customer’s existing details. The ‘Close’ button shuts down the application.

Application Architecture

This application follows an n-tier architecture pattern with different logical and physical layers, as shown in the diagram below:

NorthwindNTierBlueprint/northwindblueprintarchitecture.jpg

Presentation Layer

Windows Presentation Foundation or WPF, which provides a unified programming model for building rich Windows smart client user experiences, is used for the Presentation Layer.

The user interface of this application is composed of windows and pages defined using XAML. All the user controls, images, styles, and other resources that make up the user interface will be part of this layer. The controls are bound to commands that are defined in a separate component. The command component will have proxy classes as service references pointing to the services exposed by the service layer.

Service Layer

Windows Communication Foundation or WCF is used as the communication interface between the presentation layer and the business logic layer. The service layer consists of service contract interfaces and a host that exposes the services.

Business Logic Layer

The business logic layer is implemented as a set of assemblies (DLLs) in .NET 3.5. This layer would abstract the implementation of the business rules required for the business.

Business entity classes decorated with serialization attributes are used for transporting data across layers.

Data Access Layer

This layer provides functions that abstract the interaction with the database. Language Integrated Query or LINQ (specifically LINQ to SQL) is used in the data access layer for accessing data from the database. There is a DataHelper class which encapsulates the management of the LINQ to SQL data context. All the data access classes will pass the LINQ queries through the DataHelper class to the data context. LINQ entities are used to hold the data, and they are converted to business entities before passing to the upper layer.

Core Services

Core services are independent of business functionalities, and exist to provide basic infrastructure support. It provides reusability, and support common functionalities like error handling, logging, transaction management, etc. The services of this component are used across all layers.

Database Server

There will be only one central database for this application, which would reside on an SQL Server 2005 database server. The database will have just the tables to hold data, and no business logic would be implemented within the database objects.

All these layers are implemented as separate projects, as shown in the following image:

NorthwindNTierBlueprint/projectstructure.jpg

Exception Handling and Logging

This application includes an exception handling and logging mechanism as explained below. A custom exception class (within Northwind.Common) is used for managing the exceptions of this application. Custom exceptions help us to standardize the manner in which the exceptions are handled, logged, and reported. All exceptions are trapped, and used as a starting point to create a custom exception. Additionally, the custom exception can contain any other useful information. The path the exception took through the call stack is caught using a custom call stack within the custom exception. This helps to avoid all the numerous traces given by the default exception class and to focus on only the required information.

There will be situations where messages need to be logged as information when an exception happens. This is useful when exceptions are not affecting the flow of the application, but we still want to know that something is going wrong. The mechanism implemented here also provides an option to log informational messages instead of throwing an exception.

All exceptions are propagated up to the UI layer, and a friendly message is displayed to the end user. There is also an option to display the error details including the stack trace. All exceptions are logged to an error table in the database from the service layer. If database access itself fails, the exceptions are logged to a log file in the application server. If file access also fails, they are logged into the event log of the application server.

History

  • Initial version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionIncompatible Projects Pin
Robert Blot11-Jul-14 7:55
Robert Blot11-Jul-14 7:55 
QuestionCan't build project in VS 2012 Pin
Alezis12-Feb-14 3:54
professionalAlezis12-Feb-14 3:54 
AnswerRe: Can't build project in VS 2012 Pin
Member 931030817-Jun-14 6:10
Member 931030817-Jun-14 6:10 
I converted the project to VS2010 and got the same errors but managed to get rid of them by right-clicking on CustomerProxy and ErrorLogProxy in Northwind.UI.Commands and then selecting 'Update Service Reference'.
GeneralExcellent code really good, exactly how we do it at work Pin
Sacha Barber10-Jun-08 4:41
Sacha Barber10-Jun-08 4:41 
GeneralRe: Excellent code really good, exactly how we do it at work Pin
The Cool Wayfarer10-Jun-08 19:06
The Cool Wayfarer10-Jun-08 19:06 
GeneralRe: Excellent code really good, exactly how we do it at work Pin
Sacha Barber10-Jun-08 20:53
Sacha Barber10-Jun-08 20:53 
Generalexcellent concept documentation and solution/project organization... Pin
Greg Hazz10-Jun-08 4:38
Greg Hazz10-Jun-08 4:38 
GeneralRe: excellent concept documentation and solution/project organization... Pin
The Cool Wayfarer10-Jun-08 19:04
The Cool Wayfarer10-Jun-08 19:04 
GeneralMore detail would be nice Pin
Marc Clifton10-Jun-08 3:46
mvaMarc Clifton10-Jun-08 3:46 
GeneralRe: More detail would be nice Pin
The Cool Wayfarer10-Jun-08 18:59
The Cool Wayfarer10-Jun-08 18:59 
GeneralReally good article!! Pin
WebMaster10-Jun-08 1:36
WebMaster10-Jun-08 1:36 
GeneralRe: Really good article!! Pin
The Cool Wayfarer10-Jun-08 18:56
The Cool Wayfarer10-Jun-08 18:56 
GeneralReallly Great Job! Pin
Ruchit S.10-Jun-08 1:17
Ruchit S.10-Jun-08 1:17 
GeneralRe: Reallly Great Job! Pin
The Cool Wayfarer10-Jun-08 18:43
The Cool Wayfarer10-Jun-08 18:43 
GeneralRe: Reallly Great Job! Pin
Ruchit S.10-Jun-08 19:54
Ruchit S.10-Jun-08 19:54 
GeneralGood Excellent Pin
shajipd10-Jun-08 0:07
shajipd10-Jun-08 0:07 
GeneralRe: Good Excellent Pin
The Cool Wayfarer10-Jun-08 18:42
The Cool Wayfarer10-Jun-08 18:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.