Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 1.43 KB

IDISP014.md

File metadata and controls

56 lines (40 loc) · 1.43 KB

IDISP014

Use a single instance of HttpClient

Topic Value
Id IDISP014
Severity Info
Enabled True
Category IDisposableAnalyzers.Correctness
Code CreationAnalyzer

Description

Use a single instance of HttpClient.

Motivation

https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/

And:

http://byterot.blogspot.se/2016/07/singleton-httpclient-dns.html

How to fix violations

private static HttpClient Client =new HttpClient { ... };

Configure severity

Via ruleset file.

Configure the severity per project, for more info see MSDN.

Via #pragma directive.

#pragma warning disable IDISP014 // Use a single instance of HttpClient
Code violating the rule here
#pragma warning restore IDISP014 // Use a single instance of HttpClient

Or put this at the top of the file to disable all instances.

#pragma warning disable IDISP014 // Use a single instance of HttpClient

Via attribute [SuppressMessage].

[System.Diagnostics.CodeAnalysis.SuppressMessage("IDisposableAnalyzers.Correctness", 
    "IDISP014:Use a single instance of HttpClient", 
    Justification = "Reason...")]