Understand Code Dependencies with Visual Studio

Raymond Tang Raymond Tang 0 2117 0.54 index 10/11/2014

Visual Studio provides a convenient tool to generate visual code dependencies. It helps to identity circular references issues and also hubs.

To learn more details about this function, visit http://msdn.microsoft.com/library/dd409453(VS.110).aspx.

Find the tool

Go to menu “Architecture –> Generate Dependency Graph” and you will be able to generate the visual diagrams for your projects or solution.

https://api.kontext.tech/resource/391ada15-580c-5baa-b16f-eeb35d9b1122

Sample – Hub

https://api.kontext.tech/resource/b7d55bf4-7057-5113-85c8-141871bf7635

ContextProject.DataServices.The above diagram shows how my projects reference to each other.  Three projects are Hubs: ContextProject.Website, ContextProject.DataServices.Syndication, ContextProject.DataServices.MetaWeblog and ContextProject.DataServices, which implies that they are the top 25% highly connected nodes.

https://api.kontext.tech/resource/d6ed313e-533a-55a6-aa06-4c00bc132812

Because of these dependencies, it is hard to change and maintain the code. We can refactor can components to reduce the complexity of dependencies.

Sample – Circular Reference

Expand the assembly nodes,  we can identify the circular references.

https://api.kontext.tech/resource/751af8b4-32a7-55bc-9fad-8bfbcbbf4237

In the above diagram, three namespaces form a circular reference. Drilling-down to details, I find out the static property Configurations caused this issue.

https://api.kontext.tech/resource/a4c08562-50fa-5599-939c-eb6f2a83a362

Sample – Other

I am planning to replace my IoC component NInject with Microsoft Unity. The visual dependency diagram can help me to find out all the classes/properties/methods I need to change.

https://api.kontext.tech/resource/61c97311-bb14-5679-99fc-98497a701292

Summary

The visual dependencies can help us identify code that might be overly complex or that might need improvement. It will be very useful when you begin to analyze a new project you didn’t work on before.


Join the Discussion

View or add your thoughts below

Comments