Recently Microsoft Patterns & Practices released an updated version of the Application Architecture Guide. This guide is an invaluable source of information for anyone creating .NET applications. If you are looking for ways to structure your application, for challenges of specific application types or for non-functional requirements, you should read this document. Below is a fragment of the introduction:
“The purpose of the Application Architecture Guide 2.0 is to improve your effectiveness when building applications on the Microsoft platform. The primary audience for this guide is solution architects and development leads. The guide provides design-level guidance for the architecture and design of applications built on the Microsoft .NET platform. It focuses on the most common types of applications and on partitioning application functionality into layers, components, and services, and also walks through their key design characteristics.”
The document consists of 387 pages, which may seem big. If there is just one thing you should take away from the guide, I would say it is the following diagram. It is the reference architecture of a general application that has layers for presentation, services, business and data logic. It also connects to data sources and other services and has cross-cutting concerns like security and operations.
Immediately after the guide appeared Clemens wrote a great post about AppArch guide 2.0 and Visual Studio 2010. Since I realized that most are now working in Visual Studio 2008, I thought I would create some visuals in the current technology. So to start I created a new solution and added an Application Diagram that would contain all elements. Normally when designing top-down you create a conceptual design, which you can also do by adding a System Diagram as the conceptual design and for each of the elements on your conceptual design add other System Diagrams. The below image is what you end up with: A diagram in Visual Studio that contains all your layers of the above reference architecture.
In each of the system diagrams that represent the layers you can now add components from the reference architecture. For instance add service interfaces and message types to the services layer. For the presentation it could look like this.
Normally you can not add Class Libraries to diagrams. To be able to use the red shape, you can use power tools for VSTS Architecture Edition, which were developed for Beta2 but they work fine in Visual Studio 2008 RTM and SP1.
When you are done your application diagram will look similar to this. I think this approach is great to create levels of abstraction: The diagram containing the layers describes how you separate layers and the application diagram shows the actual projects.
When you right-click on the application diagram you can select “implement all applications”, which will generate projects and references for all items in the diagram. Your solution is now almost done. The one thing missing compared to the reference architecture is the cross-cutting concerns, for which you can use Enterprise Library. Enterprise Library is a great framework that takes care of plumbing for caching, data access, etc. Just add EntLib, or your preferred framework, to your solution and you are ready to go. Remember, if you have any questions, check out the AppArch guide and the knowledge base.