One of the pretty cool new features of Visual Studio 2010 (in the Premium and Ultimate) is that they have provided you basic modeling abilities inside the IDE. One of the new features is the Layer Diagram. A Layer Diagram allows you to visually see how your various components (from assembly all the way down to methods) interact and relate. One great feature that the Layer Diagram provides you is a way to be able to take a snapshot of your systems architecture and later perform validation against that snapshot to see if your code still conforms to your desired layout.
In this post we will review how to create a layer diagram and then how to validate your architecture against that diagram.
- Creating the Diagram…
To create a new Layer Diagram use Architecture –> New Diagram –> Layer Diagram (you will see the dialog below)
If you have not already created a new Modeling Project (new project type in VS) you will be asked to do so now. If you already have one just associate this new diagram to that project.
- Adding Layers to the Diagram…
Once you have created your new layer diagram it is time to start adding layers (components) to it. You do this by opening the Architecture Explore (View –> Architecture Explorer). When you open the explorer it should look something like below.
Now that you have the explorer open, simply drag on items from the view onto canvas as such:
Take notice that there are no association lines in the diagram above, that is because I have not added them yet. To add them I can either do it the hard way, or the easy way. The hard way involves me manually adding the association between each later, the easy way is by having the system do it. I am going to choose the easy way here. To add them automatically just right click on the canvas and click ‘Generate Dependencies’. Doing this will allow VS to determine your current associations and set them up for you.
Once VS is done, the canvas should look like below:
- Validating your Architecture…
Lets pretend that some time has gone by and you want to double check to see if your code still reflects your desired architecture as you laid out previous. To do this you simply need to open the diagram and click ‘Validate Architecture’
After clicking ‘Validate Architecture’ VS will spin through and verify your architecture. If it is found to still be ‘valid’ you will get no errors. If it is no longer valid you will get errors like below:
If/When you receive errors you need to determine if the original layout needs to be adjusted, or if there are indeed violations. If there are violations you should fix them and then rerun the validation to ensure you have corrected everything.
Now, that was pretty easy and very, very powerful. This is one of the great new features of the IDE and I cannot wait to start using it on all my projects.
Till next time,
03-21-2010 12:45 PM