SonarQube 6将DI注入的变量标记为我的构造函数,作为违反规则的关键。由于我们在所有类上使用构造函数注入它们的依赖项,因此该规则对构造函数设置的字段没有任何意义。我可以停用规则但是我会错过所有相关的方法,它确实可能是一个问题。
有没有人有解决方案或想法如何处理这个问题? This is the rule documentation
public class SomeService
{
private readonly IRequestMapper _requestMapper;
private readonly IResponseMapper _responseMapper;
public SomeService(IRequestMapper requestMapper, IResponseMapper responseMapper)
{
this._requestMapper = requestMapper;
this._responseMapper = responseMapper;
}
public string GetString()
{
// only if you don't use the dependencies, you get the the SonarQube error
return "nothing";
}
}
public interface IResponseMapper
{
string MapResponse(string response);
}
public interface IRequestMapper
{
string CreateRequest();
}