/// <summary> /// Register <see cref="PerformanceDiagnosticObserverBase"/> services. /// </summary> /// <param name="services"><see cref="IServiceCollection"/>.</param> /// <param name="configureOptions">An <see cref="Action{PerformanceMeterOptions}"/> to configure options for Unchase.FluentPerformanceMeter.</param> public static IServiceCollection AddPerformanceDiagnosticObserver <TClass>(this IServiceCollection services, Action <PerformanceMeterMvcOptions <TClass> > configureOptions = null) where TClass : ControllerBase { if (configureOptions != null) { services.Configure(configureOptions); } services.Configure <PerformanceMeterMvcOptions <TClass> >(o => PerformanceMeter <TClass> .Configure(o)); services.TryAddEnumerable( ServiceDescriptor.Transient <PerformanceDiagnosticObserverBase, PerformanceDiagnosticObserver <TClass> >()); return(services); }
/// <summary> /// Register Unchase.FluentPerformanceMeter services. /// </summary> /// <param name="services"><see cref="IServiceCollection"/>.</param> /// <param name="configureOptions">An <see cref="Action{PerformanceMeterMvcOptions}"/> to configure options for Unchase.FluentPerformanceMeter.</param> public static IServiceCollection AddPerformanceMeter <TClass>(this IServiceCollection services, Action <PerformanceMeterMvcOptions <TClass> > configureOptions = null) where TClass : ControllerBase { // ensure that IHttpContextAccessor was added services.AddHttpContextAccessor(); if (configureOptions != null) { services.Configure(configureOptions); } services.Configure <PerformanceMeterMvcOptions <TClass> >(o => { PerformanceMeter <TClass> .Configure(o); }); services.AddScoped(typeof(PerformanceMeter <TClass>), serviceProvider => { var httpContext = serviceProvider.GetRequiredService <IHttpContextAccessor>()?.HttpContext; return(httpContext?.Items[$"PerformanceMeter{httpContext.TraceIdentifier}"]); }); return(services); }