11using System ;
2- #if ! NETSTANDARD13
32using System . Net ;
4- #endif
53using System . Reflection ;
64using Microsoft . AspNetCore . Builder ;
75using Microsoft . AspNetCore . Hosting ;
@@ -46,7 +44,7 @@ public MetricServer(ICollectorRegistry registry, MetricServerOptions options)
4644 if ( string . IsNullOrEmpty ( options . MapPath ) || ! options . MapPath . StartsWith ( "/" ) )
4745 throw new ArgumentException ( $ "mapPath '{ options . MapPath } ' should start with '/'") ;
4846
49- _registry = registry ?? Metrics . DefaultCollectorRegistry ;
47+ _registry = registry ;
5048 _options = options ;
5149 }
5250
@@ -68,15 +66,8 @@ public void Start()
6866 . UseConfiguration ( config )
6967 . UseKestrel ( options =>
7068 {
71- #if NETSTANDARD13
72- if ( _options . Certificate != null )
73- options . UseHttps ( _options . Certificate ) ;
74- #endif
75-
76- #if ! NETSTANDARD13
7769 if ( _options . Certificate != null )
7870 options . Listen ( IPAddress . Any , _options . Port , listenOptions => { listenOptions . UseHttps ( _options . Certificate ) ; } ) ;
79- #endif
8071 } )
8172 . UseUrls ( $ "http{ ( _options . Certificate != null ? "s" : "" ) } ://{ _options . Host } :{ _options . Port } ")
8273 . ConfigureServices ( services => { services . AddSingleton < IStartup > ( new Startup ( _registry , _options . MapPath ) ) ; } )
@@ -100,7 +91,7 @@ internal class Startup : IStartup
10091 {
10192 private const string _contentType = "text/plain; version=0.0.4" ;
10293
103- private readonly ICollectorRegistry _registry ;
94+ private ICollectorRegistry _registry ;
10495 private readonly string _mapPath ;
10596
10697 public Startup ( ICollectorRegistry registry , string mapPath )
@@ -121,6 +112,9 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
121112
122113 public void Configure ( IApplicationBuilder app )
123114 {
115+ _registry ??= ( ICollectorRegistry ) app . ApplicationServices . GetService ( typeof ( ICollectorRegistry ) )
116+ ?? Metrics . DefaultCollectorRegistry ;
117+
124118 app . Map ( _mapPath , coreapp =>
125119 {
126120 coreapp . Run ( async context =>
0 commit comments