Skip to content

Commit 475397d

Browse files
committed
Use DI container to retrieve CollectorRegistry
1 parent e08aeb4 commit 475397d

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/Prometheus.Client.AspNetCore/Prometheus.Client.AspNetCore.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Description>Middleware for the Prometheus.Client</Description>
4-
<Copyright>2018 © Sergey Kuznetsov</Copyright>
4+
<Copyright>2020 © Serge K, Oleksandr Poliakov</Copyright>
55
<AssemblyTitle>Prometheus.Client.AspNetCore</AssemblyTitle>
6-
<VersionPrefix>4.0.0</VersionPrefix>
7-
<Authors>Sergey Kuznetsov</Authors>
6+
<VersionPrefix>4.1.0</VersionPrefix>
7+
<Authors>Serge K, Oleksandr Poliakov</Authors>
88
<TargetFrameworks>netstandard2.0;netcoreapp2.2;netstandard2.1;netcoreapp3.1</TargetFrameworks>
99
<AssemblyName>Prometheus.Client.AspNetCore</AssemblyName>
1010
<PackageId>Prometheus.Client.AspNetCore</PackageId>
@@ -33,7 +33,7 @@
3333
</None>
3434
</ItemGroup>
3535
<ItemGroup>
36-
<PackageReference Include="Prometheus.Client" Version="4.0.0" />
36+
<PackageReference Include="Prometheus.Client" Version="4.1.0" />
3737
</ItemGroup>
3838
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
3939
<FrameworkReference Include="Microsoft.AspNetCore.App" />

src/Prometheus.Client.AspNetCore/PrometheusExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Prometheus.Client.Collectors;
33
using Microsoft.AspNetCore.Builder;
44
using Microsoft.AspNetCore.Http;
5+
using Prometheus.Client.Collectors.Abstractions;
56

67
namespace Prometheus.Client.AspNetCore
78
{
@@ -35,6 +36,10 @@ public static IApplicationBuilder UsePrometheusServer(this IApplicationBuilder a
3536
if (!options.MapPath.StartsWith("/"))
3637
throw new ArgumentException($"MapPath '{options.MapPath}' should start with '/'");
3738

39+
options.CollectorRegistryInstance
40+
??= (ICollectorRegistry)app.ApplicationServices.GetService(typeof(ICollectorRegistry))
41+
?? Metrics.DefaultCollectorRegistry;
42+
3843
if (options.UseDefaultCollectors)
3944
options.CollectorRegistryInstance.UseDefaultCollectors();
4045

src/Prometheus.Client.AspNetCore/PrometheusOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public class PrometheusOptions
1818
public int? Port { get; set; }
1919

2020
/// <summary>
21-
/// CollectorRegistry intance
21+
/// CollectorRegistry instance.
2222
/// </summary>
23-
public ICollectorRegistry CollectorRegistryInstance { get; set; } = Metrics.DefaultCollectorRegistry;
23+
public ICollectorRegistry CollectorRegistryInstance { get; set; }
2424

2525
/// <summary>
2626
/// Use default collectors

0 commit comments

Comments
 (0)