10

Resharper warns me when parts of my code are never used; this is very helpful.

However, I have quite a few classes that are not referenced by other code directly. These classes are used in the dependency injection (DI) configuration only.

I use spring.net for DI. The DI configuration is in xml format.

Is there any way I can tell Resharper to use the DI files for the inspection of unused classes?

I know I can suppress the Resharper warning using something like:

// ReSharper disable UnusedMember.Global
public class TheClass : IInterfaceWiredUsingSpringDI
// ReSharper restore UnusedMember.Global

But I don't like this very much - it's difficult to read and I don't really want to suppress the warning.

Note:

There is a less obtrusive and more readable way to suppress the warning, which I found on the jetbrains forum. When you define this custom attribute:

[MeansImplicitUse]
public class IoCAttribute : Attribute { }

Then you can suppress the warning:

[IoC]
public class TheClass : IInterfaceWiredUsingSpringDI 
Marijn
  • 10,367
  • 5
  • 59
  • 80
  • 1
    I know is quite a move from what you have, but if you use one of the spring fluent configuration alternatives resharper would be able to detect it (because it would be referenced by actual code) – Sebastian Piu Nov 25 '10 at 13:25
  • Good idea, but I actually like the xml configs in a production environment. – Marijn Nov 25 '10 at 14:31
  • Maybe I could use a fluent config in development, that would work. I'll look into it. – Marijn Nov 25 '10 at 14:33
  • I'm about to do the same, have it programmatically while in development and then do an "export" of it if I feel is necessary – Sebastian Piu Nov 26 '10 at 19:59
  • It might be interesting to watch this project: https://github.com/SpringSource/spring-net-codeconfig. It's a code config project for spring.net, by some of the spring.net devs (Mark Pollack and Steve Bohlen have contributed, as it appears). – Marijn Dec 21 '10 at 13:46
  • This is a sample configuration: https://github.com/SpringSource/spring-net-codeconfig/blob/master/examples/Spring.IoCQuickStart.MovieFinder/src/MovieFinder/MovieFinderConfiguration.cs – Marijn Dec 21 '10 at 13:50
  • just noticed a fluent config api on github: https://github.com/thenapoleon/Fluent-API-for-Spring.Net – Marijn Mar 08 '11 at 12:35
  • Interestingly, there IS a project designed precisely designed to find DI configuration for ReSharper. http://hmemcpy.github.com/AgentMulder/ It does NOT, however, support Spring.NET and its extendability seems limited to code-based configuration, not XML or maybe even attributes, but it could probably be made to work with spring codeconfig. – Avi Cherry Nov 30 '12 at 21:47

2 Answers2

7

I'm 3 years too late to answer this, but I just saw this question via ReSharper's twitter stream. I created a plugin for ReSharper called Agent Mulder, and it does exactly this -- analyzes IoC container registrations, and allows navigating and finding usages of types that are registered via the container!

For the list of supported containers, please visit the project's wiki on github.

(Unfortunately, it doesn't work with Spring.NET, since there was no demand for it, sorry :))

Igal Tabachnik
  • 31,174
  • 15
  • 92
  • 157
4

I don't believe so. Spent a bit of time trying to solve a similar frustration with IOC and ReSharper to no avail, just doesn't facilitate it as far as I can tell.

Timbo
  • 4,505
  • 2
  • 26
  • 29
  • 1
    It's understandable that they don't work with it. They would pretty much have to code for each common DI implementation and then change it if the xml mapping schema changed or whatever... – Timbo Nov 26 '10 at 10:57
  • I don't hold it against them :-) – Marijn Nov 26 '10 at 13:26
  • I couldn't find anything either; I'll accept this as the answer. – Marijn Nov 26 '10 at 13:31