11using System ;
2- using System . Collections . Generic ;
32using System . Net ;
43using System . Net . Sockets ;
54using System . Threading ;
@@ -42,25 +41,22 @@ public static HealthCheckService EnableHealthCheck(
4241 int port ,
4342 string path = "/health/" )
4443 {
45- if ( server == null )
46- {
47- throw new ArgumentNullException ( nameof ( server ) ) ;
48- }
44+ ArgumentNullException . ThrowIfNull ( server ) ;
4945
5046 if ( string . IsNullOrWhiteSpace ( hostname ) )
5147 {
5248 throw new ArgumentNullException ( nameof ( hostname ) ) ;
5349 }
5450
5551 // Ensure path ends with /
56- if ( ! path . EndsWith ( "/" ) )
52+ if ( ! path . EndsWith ( '/' ) )
5753 {
58- path += "/" ;
54+ path += '/' ;
5955 }
6056
6157 HealthCheckServiceOptions options = new ( )
6258 {
63- Prefixes = new List < string > { $ "http://{ hostname } :{ port } { path } " }
59+ Prefixes = new ( ) { $ "http://{ hostname } :{ port } { path } " }
6460 } ;
6561
6662 HealthCheckService service = new ( options , server . Configuration . LoggerFactory ) ;
@@ -86,15 +82,9 @@ public static HealthCheckService EnableHealthCheck(
8682 int port ,
8783 string path = "/health/" )
8884 {
89- if ( server == null )
90- {
91- throw new ArgumentNullException ( nameof ( server ) ) ;
92- }
85+ ArgumentNullException . ThrowIfNull ( server ) ;
9386
94- if ( ipAddress == null )
95- {
96- throw new ArgumentNullException ( nameof ( ipAddress ) ) ;
97- }
87+ ArgumentNullException . ThrowIfNull ( ipAddress ) ;
9888
9989 string hostname = ipAddress . ToString ( ) ;
10090 if ( ipAddress . AddressFamily == AddressFamily . InterNetworkV6 )
@@ -117,15 +107,9 @@ public static HealthCheckService EnableHealthCheck(
117107 HealthCheckServiceOptions serviceOptions ,
118108 SmtpHealthCheckOptions ? healthCheckOptions = null )
119109 {
120- if ( server == null )
121- {
122- throw new ArgumentNullException ( nameof ( server ) ) ;
123- }
110+ ArgumentNullException . ThrowIfNull ( server ) ;
124111
125- if ( serviceOptions == null )
126- {
127- throw new ArgumentNullException ( nameof ( serviceOptions ) ) ;
128- }
112+ ArgumentNullException . ThrowIfNull ( serviceOptions ) ;
129113
130114 HealthCheckService service = new ( serviceOptions , server . Configuration . LoggerFactory ) ;
131115
@@ -218,20 +202,14 @@ public static HealthCheckService AddHealthCheck(
218202 string name ,
219203 Func < CancellationToken , Task < HealthCheckResult > > healthCheckFunc )
220204 {
221- if ( service == null )
222- {
223- throw new ArgumentNullException ( nameof ( service ) ) ;
224- }
205+ ArgumentNullException . ThrowIfNull ( service ) ;
225206
226207 if ( string . IsNullOrWhiteSpace ( name ) )
227208 {
228209 throw new ArgumentNullException ( nameof ( name ) ) ;
229210 }
230211
231- if ( healthCheckFunc == null )
232- {
233- throw new ArgumentNullException ( nameof ( healthCheckFunc ) ) ;
234- }
212+ ArgumentNullException . ThrowIfNull ( healthCheckFunc ) ;
235213
236214 FunctionalHealthCheck functionalHealthCheck = new ( healthCheckFunc ) ;
237215 service . AddHealthCheck ( name , functionalHealthCheck ) ;
@@ -243,14 +221,9 @@ public static HealthCheckService AddHealthCheck(
243221 /// <summary>
244222 /// Functional health check implementation
245223 /// </summary>
246- internal class FunctionalHealthCheck : IHealthCheck
224+ internal class FunctionalHealthCheck ( Func < CancellationToken , Task < HealthCheckResult > > checkFunc ) : IHealthCheck
247225 {
248- private readonly Func < CancellationToken , Task < HealthCheckResult > > _checkFunc ;
249-
250- public FunctionalHealthCheck ( Func < CancellationToken , Task < HealthCheckResult > > checkFunc )
251- {
252- _checkFunc = checkFunc ?? throw new ArgumentNullException ( nameof ( checkFunc ) ) ;
253- }
226+ private readonly Func < CancellationToken , Task < HealthCheckResult > > _checkFunc = checkFunc ?? throw new ArgumentNullException ( nameof ( checkFunc ) ) ;
254227
255228 public Task < HealthCheckResult > CheckHealthAsync ( CancellationToken cancellationToken = default )
256229 {
0 commit comments