-
Notifications
You must be signed in to change notification settings - Fork 729
/
ManualHealthCheck.cs
57 lines (46 loc) · 1.33 KB
/
ManualHealthCheck.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Diagnostics.CodeAnalysis;
namespace Microsoft.Extensions.Diagnostics.HealthChecks;
internal sealed class ManualHealthCheck<T> : IManualHealthCheck<T>
{
private static readonly object _lock = new();
private HealthCheckResult _result;
public HealthCheckResult Result
{
get
{
lock (_lock)
{
return _result;
}
}
set
{
lock (_lock)
{
_result = value;
}
}
}
private readonly ManualHealthCheckTracker _tracker;
[SuppressMessage("Major Code Smell", "S3366:\"this\" should not be exposed from constructors", Justification = "It's OK, just registering into a list")]
public ManualHealthCheck(ManualHealthCheckTracker tracker)
{
Result = HealthCheckResult.Unhealthy("Initial state");
_tracker = tracker;
_tracker.Register(this);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose(bool _)
{
_tracker.Unregister(this);
}
[ExcludeFromCodeCoverage]
~ManualHealthCheck() => Dispose(false);
}