Click here to Skip to main content
Email Password   helpLost your password?

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.

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:

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:

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

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralExcellent code really good, exactly how we do it at work
Sacha Barber
5:41 10 Jun '08  
Excellent code really good, exactly how we do it at work...But the article needs to talk a bit more about it, after all its good code, do yourself some credit and update the article text

Sacha Barber
  • Microsoft Visual C# MVP 2008
  • Codeproject MVP 2008
Your best friend is you.
I'm my best friend too. We share the same views, and hardly ever argue

My Blog : sachabarber.net

GeneralRe: Excellent code really good, exactly how we do it at work
The Cool Wayfarer
20:06 10 Jun '08  
Thanks Sacha Barber. Yeah... I now understand the importance of better documentation to do justice to that hard work on the code. Will surely find time to update this article sooner or later.

The Cool Wayfarer

GeneralRe: Excellent code really good, exactly how we do it at work
Sacha Barber
21:53 10 Jun '08  
Make sure you do, its actually good code, though I think the service/interface and service code could have been in 1 project hosted in ISS. Cant see the point of splitting this into 3 projects.

But cool none the less

Sacha Barber
  • Microsoft Visual C# MVP 2008
  • Codeproject MVP 2008
Your best friend is you.
I'm my best friend too. We share the same views, and hardly ever argue

My Blog : sachabarber.net

Generalexcellent concept documentation and solution/project organization...
Greg Hazzard
5:38 10 Jun '08  
..and all I have to do is change the connection strings in app.config and it works! What a great first impression! Now I have to figure out why it takes 13-14 seconds for the populated grid to appear after pressing the LOAD button on my laptop. I can see the code initially walking through CustomerCommands but the latency is somewhere else I'm sure. hmmmmm. it's worth tracking down. -greg
GeneralRe: excellent concept documentation and solution/project organization...
The Cool Wayfarer
20:04 10 Jun '08  
Thanks Greg. It takes similar latency on my laptop too. Did'nt have much time to investigate further on that. Command Pattern provides excellant separation of UI controls and the actual code they execute. It should not cause any latency. Let me know if you find something interesting. I will post an update to this if I get more time to spend on this.

The Cool Wayfarer

GeneralMore detail would be nice
Marc Clifton
4:46 10 Jun '08  
Your intro is great, but the article lacks the detail to back up your claims. Do you think you could expand on exactly how this blueprint uses the .NET 3.5 technologies you mention?

Marc


GeneralRe: More detail would be nice
The Cool Wayfarer
19:59 10 Jun '08  
That's a good point Marc. I was busy focussing on the code and had not much time in my hand to come up with a best documentation for it. I'll see if I can update this article with more info as you mentioned. Thanks for the suggestion.

The Cool Wayfarer

GeneralReally good article!!
Browski
2:36 10 Jun '08  
This is perfect for me as I'm new to 3.5 and I'm now able to visualize what goes where. i.e. WCF sits in between the UI layer and the Business Layer.

Great Job!!!!
GeneralRe: Really good article!!
The Cool Wayfarer
19:56 10 Jun '08  
Thanks Browski. You might also be interested in an article that talks about various options when you are using LINQ. Here is that: Keith Craig's Blog[^]

The Cool Wayfarer

GeneralReallly Great Job!
Ruchit Surati
2:17 10 Jun '08  
on such a powerful platform like .net 3.x its always tough to conclude over a good scalable design.

this article really makes a difference!

Ruchit S.
http://ruchitsurati.net

******************************************

GeneralRe: Reallly Great Job!
The Cool Wayfarer
19:43 10 Jun '08  
Thanks Ruchit for the encouraging words.

The Cool Wayfarer

GeneralRe: Reallly Great Job!
Ruchit Surati
20:54 10 Jun '08  
in fact, what you've done, is again a new way of putting parallel tiers in the app. for extensibility and accessibility. May be I can just attach another tier parallel to service host to allow web servoces driven public services to my enterprise system. Simply superb. I can think of being able to implement various microsoft .net projects like astoria, ado.net entity model, linq2sql, typed-datasets for different purposes. After you know/learn all the approaches to do one single thing, your headache is to select one single approach and through out the project life cycle you'd think I should have done it the other way.

Great job, dude!

I also chked out ur website, it is as cool as your article.


kepp doing the great job! and all d best!


Thanks..

Ruchit S.
http://ruchitsurati.net

******************************************

GeneralGood Excellent
shajipd
1:07 10 Jun '08  
I have been looking for a good architectural solution for my recent project.
This seems to be an excellent article with sample,
for people who are looking for Architectural solution for N tier Applications..
GeneralRe: Good Excellent
The Cool Wayfarer
19:42 10 Jun '08  
Thanks Shaji. I just want to remind you that there are many options out there when you are going for a best architectural solution... and this is just one option out of them.

The Cool Wayfarer


Last Updated 10 Jun 2008 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010