Monday, November 23, 2009

[Tutorial] How to use Layer Diagrams in Visual Studio 2010 for Architecture Validation Part 3

In the last part we added a Layer Diagram, created some layers and added references to all projects within the example project. This time I will show you how to append projects namespaces or even classes  to the different layers using a new tool called Architecture Explorer. I will then show you how to validate you project based on the layer relations.

Using the Architecture Explorer

The Architecture Explorer is a new tool inside Visual Studio 2010. It serves to understand code structure and to interact with different elements in your code (namespaces, classes, methods, etc…). You can use the Class View or the Solution View to filter and  see what is inside your solution.

  • Open the Architecture Explorer (activate it from the menu if you do not see it in your IDE)
  • Click on Solution View, you will see the different folders and the new Architecture project in the window
  • Click on the Business folder and you will its containing projects


Defining content in Layers

  • Open the Layer Diagram you created in the last part of the series
  • Display the Layer Diagram and Architecture Explorer
  • Select the contents of the Business folder (5 projects)


  • Drag and drop them from the Architecture Explorer onto the Business Layer in the Layer Diagram
  • Do the same for all other layers (I added the Hosts & UI projects to the Presentation Layer)


  • The layers now contain numbers on the leftmost edge, these numbers represent how many projects are contained by the layer (if you added namespaces it would be the number of namespaces, etc…)


Validating the Architecture

  • Do a right click on the Layer Diagram to open the context menu, you will see the option to validate the architecture


  • Validate the Architecture, a new screen will pop up and the validations starts


  • At the end of the validation you will see a report that either says that everything was successful or that there were errors

Validation Errors (a good thing!)

  • In our case we will get 114 errors with the information “AV001: Invalid Dependency …”
  • This means that the source code does not adhere to the architecture design that was defined in the Layer Diagram


  • If you double click on the first error it will take you to the line of code that generated the validation exception, you may now analyze the source of the problem

You might already know why this doesn’t work, anyways stay tuned until the next article, where I explain in detail what happened and what needs to be done next.


No comments: