Skip to content

Commit 0838d81

Browse files
authored
Enable nullable on HealthChecks.EntityFrameworkCore (#28815)
1 parent 7b85d7c commit 0838d81

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

src/Middleware/HealthChecks.EntityFrameworkCore/src/DbContextHealthCheckOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -10,6 +10,6 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks
1010
{
1111
internal sealed class DbContextHealthCheckOptions<TContext> where TContext : DbContext
1212
{
13-
public Func<TContext, CancellationToken, Task<bool>> CustomTestQuery { get; set; }
13+
public Func<TContext, CancellationToken, Task<bool>>? CustomTestQuery { get; set; }
1414
}
1515
}

src/Middleware/HealthChecks.EntityFrameworkCore/src/DependencyInjection/EntityFrameworkCoreHealthChecksBuilderExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using System.Threading;
78
using System.Threading.Tasks;
89
using Microsoft.EntityFrameworkCore;
@@ -54,10 +55,10 @@ public static class EntityFrameworkCoreHealthChecksBuilderExtensions
5455
/// </remarks>
5556
public static IHealthChecksBuilder AddDbContextCheck<TContext>(
5657
this IHealthChecksBuilder builder,
57-
string name = null,
58+
string? name = null,
5859
HealthStatus? failureStatus = default,
59-
IEnumerable<string> tags = default,
60-
Func<TContext, CancellationToken, Task<bool>> customTestQuery = default)
60+
IEnumerable<string>? tags = default,
61+
Func<TContext, CancellationToken, Task<bool>>? customTestQuery = default)
6162
where TContext : DbContext
6263
{
6364
if (builder == null)
@@ -75,7 +76,7 @@ public static IHealthChecksBuilder AddDbContextCheck<TContext>(
7576
builder.Services.Configure<DbContextHealthCheckOptions<TContext>>(name, options => options.CustomTestQuery = customTestQuery);
7677
}
7778

78-
return builder.AddCheck<DbContextHealthCheck<TContext>>(name, failureStatus, tags);
79+
return builder.AddCheck<DbContextHealthCheck<TContext>>(name, failureStatus, tags ?? Enumerable.Empty<string>());
7980
}
8081
}
8182
}

src/Middleware/HealthChecks.EntityFrameworkCore/src/Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<PackageTags>diagnostics;healthchecks;entityframeworkcore</PackageTags>
1010
<BaseNamespace>Microsoft.Extensions.Diagnostics.HealthChecks</BaseNamespace>
11+
<Nullable>enable</Nullable>
1112
</PropertyGroup>
1213

1314
<ItemGroup>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#nullable enable
22
Microsoft.Extensions.DependencyInjection.EntityFrameworkCoreHealthChecksBuilderExtensions
3-
~static Microsoft.Extensions.DependencyInjection.EntityFrameworkCoreHealthChecksBuilderExtensions.AddDbContextCheck<TContext>(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = null, System.Collections.Generic.IEnumerable<string> tags = null, System.Func<TContext, System.Threading.CancellationToken, System.Threading.Tasks.Task<bool>> customTestQuery = null) -> Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder
3+
static Microsoft.Extensions.DependencyInjection.EntityFrameworkCoreHealthChecksBuilderExtensions.AddDbContextCheck<TContext>(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder! builder, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = null, System.Collections.Generic.IEnumerable<string!>? tags = null, System.Func<TContext!, System.Threading.CancellationToken, System.Threading.Tasks.Task<bool>!>? customTestQuery = null) -> Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder!

0 commit comments

Comments
 (0)