Skip to content

Commit 34680f6

Browse files
committed
feat: use di in hc
1 parent 664e263 commit 34680f6

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

Prometheus.Client.Examples.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleMetricServer_6.0", "
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreWebWithoutExtensions_3.1", "src\CoreWebWithoutExtensions_3.1\CoreWebWithoutExtensions_3.1.csproj", "{A03FD2F8-8F18-44AB-9D01-16D15208B087}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecks_6.0", "src\HealthChecks_6.0\HealthChecks_6.0.csproj", "{237FECAD-9D7C-43F4-A240-974A5ADE0DE7}"
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecks", "src\HealthChecks\HealthChecks.csproj", "{237FECAD-9D7C-43F4-A240-974A5ADE0DE7}"
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore_6.0", "src\AspNetCore_6.0\AspNetCore_6.0.csproj", "{297EA5CD-C468-40CA-A97C-8A5DC28CF701}"
1313
EndProject

src/HealthChecks_6.0/HealthChecks_6.0.csproj renamed to src/HealthChecks/HealthChecks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="6.0.3" />
99
<PackageReference Include="Prometheus.Client" Version="5.2.0" />
1010
<PackageReference Include="Prometheus.Client.AspNetCore" Version="5.0.0" />
11+
<PackageReference Include="Prometheus.Client.DependencyInjection" Version="1.4.0" />
1112
<PackageReference Include="Prometheus.Client.HealthChecks" Version="2.0.0" />
1213
</ItemGroup>
1314
</Project>
File renamed without changes.

src/HealthChecks_6.0/Startup.cs renamed to src/HealthChecks/Startup.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Prometheus.Client;
99
using Prometheus.Client.AspNetCore;
1010
using Prometheus.Client.Collectors;
11+
using Prometheus.Client.DependencyInjection;
1112
using Prometheus.Client.HealthChecks;
1213

1314
namespace HealthChecks;
@@ -21,20 +22,18 @@ public Startup(IConfiguration configuration)
2122

2223
public IConfiguration Configuration { get; }
2324

24-
// This method gets called by the runtime. Use this method to add services to the container.
2525
public void ConfigureServices(IServiceCollection services)
2626
{
2727
services.AddControllers();
28-
services.AddSingleton<ICollectorRegistry, CollectorRegistry>();
29-
services.AddSingleton<IMetricFactory, MetricFactory>();
28+
services.AddMetricFactory();
29+
3030
services
3131
.AddHealthChecks()
3232
.AddUrlGroup(new Uri("https://google.com"), "google", HealthStatus.Unhealthy)
3333
.AddUrlGroup(new Uri("https://invalidurl"), "invalidurl", HealthStatus.Degraded);
3434
services.AddPrometheusHealthCheckPublisher();
3535
}
3636

37-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
3837
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3938
{
4039
app.UseRouting();
@@ -46,7 +45,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4645

4746
app.UseHealthChecks("/hc", new HealthCheckOptions
4847
{
49-
Predicate = r => true
48+
Predicate = _ => true
5049
});
5150

5251
app.UsePrometheusServer();

0 commit comments

Comments
 (0)