简体   繁体   中英

How to suppress Resharper wide-analysis warning of properties with Inject attribute?

We use dependency injector Ninject in our C# project. The usual way of implementing it looks like this:

[Inject]
public UsersRepositoryInterface UsersRepository { private get; set; }

In addition to this, I enabled Resharper Wide Analysis for the solution, and it shows me to warnings in this line:

  • Property 'VrtSystemsFlatRepository' can be made private
  • Auto-property accessor is never used

在此输入图像描述

My inner perfectionist suffers when he sees it, and I don't know how to avoid this warning.

I know about two ways, but I don't like both of them.

  1. Add UsedImplicitly attribute in addition to Inject . The warning will be suppressed, but I need to add this Attribute to so many places.
  2. Suppress the warning globally for the solution, for the project or file.

You can configure Ninject to look for a custom attribute other than [Inject] by having the Kernel be passed a NinjectSettings with a different InjectAttribute . You should be able to inherit this custom attribute from UsedImplicitly to suppress the Resharper warning.

需要在JetBrains的外部注释包中为“ Ninject.InjectAttribute”添加“ MeansImplicitUse”注释: https : //github.com/JetBrains/ExternalAnnotations/issues/161

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM