Class ServiceCollectionExtensions
- Namespace
- Cuemon.Extensions.AspNetCore.Diagnostics
- Assembly
- Cuemon.Extensions.AspNetCore.dll
Extension methods for the IServiceCollection interface.
public static class ServiceCollectionExtensions
- Inheritance
-
ServiceCollectionExtensions
Examples
The following example demonstrates how to use the ServiceCollectionExtensions extension methods to configure diagnostics and fault handling in an ASP.NET Core application.
using System;
using Cuemon.AspNetCore.Diagnostics;
using Cuemon.Diagnostics;
using Cuemon.Extensions.AspNetCore.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
namespace MyAspNetCoreApp
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Add ServerTiming service for performance profiling
services.AddServerTiming(options =>
{
options.TimeMeasureCompletedThreshold = TimeSpan.FromMilliseconds(10);
});
// Configure FaultDescriptor options (exception handling)
services.AddFaultDescriptorOptions(options =>
{
options.SensitivityDetails = FaultSensitivityDetails.All;
options.RootHelpLink = new Uri("https://example.com/help");
});
// Configure ExceptionDescriptor options
services.AddExceptionDescriptorOptions(options =>
{
options.SensitivityDetails = FaultSensitivityDetails.None;
});
// Configure ServerTiming options separately
services.AddServerTimingOptions(options =>
{
options.TimeMeasureCompletedThreshold = TimeSpan.FromMilliseconds(50);
});
// Post-configure all IExceptionDescriptorOptions instances
services.PostConfigureAllExceptionDescriptorOptions(options =>
{
options.SensitivityDetails = FaultSensitivityDetails.FailureWithStackTrace;
});
}}
}
Methods
AddExceptionDescriptorOptions(IServiceCollection, Action<ExceptionDescriptorOptions>)
Registers the specified setup to configure ExceptionDescriptorOptions in the services collection.
public static IServiceCollection AddExceptionDescriptorOptions(this IServiceCollection services, Action<ExceptionDescriptorOptions> setup = null)
Parameters
servicesIServiceCollectionThe IServiceCollection to extend.
setupAction<ExceptionDescriptorOptions>The ExceptionDescriptorOptions that may be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
AddFaultDescriptorOptions(IServiceCollection, Action<FaultDescriptorOptions>)
Registers the specified setup to configure FaultDescriptorOptions in the services collection.
public static IServiceCollection AddFaultDescriptorOptions(this IServiceCollection services, Action<FaultDescriptorOptions> setup = null)
Parameters
servicesIServiceCollectionThe IServiceCollection to extend.
setupAction<FaultDescriptorOptions>The FaultDescriptorOptions that may be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Exceptions
- ArgumentException
setupfailed to configure an instance of FaultDescriptorOptions in a valid state.
AddServerTiming(IServiceCollection, Action<ServerTimingOptions>)
Adds a ServerTiming service to the specified IServiceCollection.
public static IServiceCollection AddServerTiming(this IServiceCollection services, Action<ServerTimingOptions> setup = null)
Parameters
servicesIServiceCollectionThe IServiceCollection to add services to.
setupAction<ServerTimingOptions>The ServerTimingOptions that may be configured.
Returns
- IServiceCollection
An IServiceCollection that can be used to further configure other services.
AddServerTimingOptions(IServiceCollection, Action<ServerTimingOptions>)
Registers the specified setup to configure ServerTimingOptions in the services collection.
public static IServiceCollection AddServerTimingOptions(this IServiceCollection services, Action<ServerTimingOptions> setup = null)
Parameters
servicesIServiceCollectionThe IServiceCollection to extend.
setupAction<ServerTimingOptions>The ServerTimingOptions that may be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Exceptions
- ArgumentException
setupfailed to configure an instance of ServerTimingOptions in a valid state.
AddServerTiming<T>(IServiceCollection, Action<ServerTimingOptions>)
Adds an implementation of IServerTiming service to the specified IServiceCollection.
public static IServiceCollection AddServerTiming<T>(this IServiceCollection services, Action<ServerTimingOptions> setup = null) where T : class, IServerTiming
Parameters
servicesIServiceCollectionThe IServiceCollection to add services to.
setupAction<ServerTimingOptions>The ServerTimingOptions that may be configured.
Returns
- IServiceCollection
An IServiceCollection that can be used to further configure other services.
Type Parameters
T
PostConfigureAllExceptionDescriptorOptions(IServiceCollection, Action<IExceptionDescriptorOptions>)
Registers an action used to post-configure all instances of IExceptionDescriptorOptions in the services collection.
These are run after Configure<TOptions>(IServiceCollection, Action<TOptions>).
public static IServiceCollection PostConfigureAllExceptionDescriptorOptions(this IServiceCollection services, Action<IExceptionDescriptorOptions> setup)
Parameters
servicesIServiceCollectionThe IServiceCollection to extend.
setupAction<IExceptionDescriptorOptions>The IExceptionDescriptorOptions which need to be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.