0

ReSharper is flagging a constructor parameter with a warning, suggesting that I change the parameter to it's inherited interface type. However I need the specific implementation as the parameter type for dependency injection reasons.

I can't seem to disable this individual suggestion. // ReSharper disable All + // ReSharper restore All did not appear to work and none of the drop down options let me ignore it.

My code is arranged somewhat like this:

// Constructor with the ReSharper warning.
IShape _shape;
public SquareConsumer(Square square){
    _shape = square;
}

// Class where I set up dependency injection using Ninject.
public void SetupBindings(IKernel kernel){
    kernel.Bind<Square>.ToSelf();
    kernel.Bind<SquareConsumer>.ToSelf();
}

I realize that I could use a more generic binding and bind "IShape" to "Square" when injected in to the "SquareConsumer", but in the context of my application it makes more sense to have a single instance of "Square" available to any class that needs to use it explicitly.

I am using ReSharper 8.2 and Visual Studio 2013 (Professional).

How can I disable this instance of the warning?

2 Answers2

3

To specifically suppress the "Parameter can be declared with base type" warning, use

// ReSharper disable once SuggestBaseTypeForParameter
ulrichb
  • 19,610
  • 8
  • 73
  • 87
0

If you just want to ignore this warning, click the gear icon on the left of the constructor line of code and select 'Inspection' - 'Disable Once with Comment'.

xtu
  • 417
  • 3
  • 12