Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm sure we've all been in the situation where we've inherited code that was "overly public", becomes obsolete or needs to be refactored. In these situations, it is easy to spend many days analysing the API surface to see where methods or classes are consumed; with the .Net runtime, it seems logical that it should be relatively trivial to map these inter-assembly dependencies, but there doesn't seem to be any tools out there that do this already?

For example, let's suggest that we have a CRM class library that encapsulates the interface to all the customer data; it's not unreasonable that a quotations application may rely on this, but it seems non-trivial to identify on which bits. A naive approach would be to say that the public interfaces (types, etc.) is the API surface, but it may be the case that some of these interfaces are only public for consumption in a particular use case, that may become invalid.

Is it possible to automatically determine and map the inter-assembly dependencies for a given set of assemblies?

share|improve this question

2 Answers 2

Static analysis tools like nDepend do this.

It has views that tell you what types are used where and how often, recognized circular dependencies and more.

share|improve this answer
    
As far as I can make out from their feature comparison, this works on a solution level, rather than "set of assemblies" level –  Rowland Shaw Feb 28 '12 at 15:22
1  
@RowlandShaw - No, it analyses assemblies. –  Oded Feb 28 '12 at 15:25
    
Well, the trial version is suitably unhelpful to confirm what I knew were dependencies in my code, but it does seem to have missed a load too, which is worrying. Perhaps I'd be better off writing something myself using the reflection APIs "at some point". –  Rowland Shaw Feb 28 '12 at 17:09

I'm sure you could identify some of the dependencies, but not all. E.g., what about a web service call that's either dynamically generated or read from a resource?

share|improve this answer
    
A webservice is actually fairly easy to define the API surface, as it would be decorated with appropriate attributes, although that's not my use case to be analysing today –  Rowland Shaw Feb 28 '12 at 17:07
    
I meant if you had a system A whose API you were analyzing, and some system B was making web service calls to A, it might be hard to determine which web services were being called if system B was dynamically generating the service URI was or was creating the service call from a template stored in a database or resource file. –  TMN Feb 28 '12 at 19:07
    
But then the web service portions would be suitably decorated, and obvious as part of the public API surface. –  Rowland Shaw Feb 28 '12 at 19:28
    
But how would you know whether it was used, or whether you could safely remove it to reduce your API exposure? –  TMN Feb 29 '12 at 13:20
    
If that API had been published, then it is never safe to remove it. In my use case, there is no published API surface. –  Rowland Shaw Feb 29 '12 at 13:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.