Tell Resharper to use spring.net DI configuration for the inspection of unused classes?
Asked Answered
V

2

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 
Valueless answered 25/11, 2010 at 12:5 Comment(8)
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)Darwen
Good idea, but I actually like the xml configs in a production environment.Valueless
Maybe I could use a fluent config in development, that would work. I'll look into it.Valueless
I'm about to do the same, have it programmatically while in development and then do an "export" of it if I feel is necessaryDarwen
It might be interesting to watch this project: 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).Valueless
This is a sample configuration: github.com/SpringSource/spring-net-codeconfig/blob/master/…Valueless
just noticed a fluent config api on github: github.com/thenapoleon/Fluent-API-for-Spring.NetValueless
Interestingly, there IS a project designed precisely designed to find DI configuration for ReSharper. 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.Procrustes
G
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.

Gadget answered 25/11, 2010 at 12:46 Comment(3)
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...Gadget
I don't hold it against them :-)Valueless
I couldn't find anything either; I'll accept this as the answer.Valueless
O
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 :))

Objectivity answered 29/5, 2013 at 6:49 Comment(0)
G
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.

Gadget answered 25/11, 2010 at 12:46 Comment(3)
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...Gadget
I don't hold it against them :-)Valueless
I couldn't find anything either; I'll accept this as the answer.Valueless

© 2022 - 2024 — McMap. All rights reserved.