Wednesday, 31 July 2013

Navigating code which uses IoC

Recently I've been navigating around lots of code which uses interfaces to implement Inversion of Control.  The problem is that every time you use F12 to 'Go To Definition' you are taken to the interface, not any of the available implementations.  Most of the time there is only one real implementation, the other(s) are for unit tests.
 
Here are your quick navigation options:

 

Put interface and implementation in the same file

A low-tech option is just to put the main implementation of the interface in the same file as the interface itself.  In reality this is often not an option.

 

Call Hierarchy

You can use the built in 'Call Hierarchy' (Ctrl+k, Ctrl-t) to show implementations of the given function.
 

 

Productivity Power Tools

Productivity Power Tools (see here) allow you to click on the interface name and see 'Implemented By'.  You can then open the list of functions to get to the function you need.

 

Code Rush

There's a plugin for CodeRush here but I couldn't get it to work (even after I remembered to Unblock the downloaded DLL).  Also I found that CodeRush made my IDE grind to a halt (the solution is VERY large)

 

Visual Assist X

Visual Assist doesn't help (but also doesn't hinder any of the other options)

 

ReSharper

Apparently if you have ReSharper then ALT+END will find all implementors.
 
Note these hints are a summary of this post.
Visual Studio user voice suggestion that the functionality is added (here)