Monday, August 4, 2014

Using layer diagrams to validate your architecture

A problem with solutions that have a more sophisticated architecture is ensuring that developers adhere to the design.  It's pretty easy for a developer to inadvertently (or on purpose) ignore the system design and code it "just so it works".  One of the tools you can use to combat this is using a layer diagram in Visual Studio 2013 to validate your architecture.  This works best when adopting this from the very beginning of a project.

  1. Add a project using the Modeling Project template.  
  2. From the Architecture menu, choose New Diagram.
  3. Choose Layer Diagram.
  4. You can drag "stuff" from both the Architecture Explorer as well as Solution Explorer.
  5. Each time you drag something to the diagram, you create a "layer" for that "artifact".
  6. I tend to group likewise classes into namespaces, so dragging namespaces from the Architecture Explorer works well for me.
  7. To create higher-level (project level) layers, instead of dragging the project into the diagram, it works better to create your own generic layer that is not tied to any code, and then dragging the namespace layers into your generic layers.
  8. You can also drag individual classes from Solution Explorer onto the diagram.
  9. Once you have all your layers defined, then select all of the layers, right click, and choose Generate Dependencies.
  10. At this point, if you right click in some white space and choose Validate Architecture, you should validate fine.
  11. If anyone goes rogue and violates your architecture, then Validate Architecture will fail and direct you to the offending code.

No comments:

Post a Comment