Table of Contents

Class ServiceCollectionExtensions

Namespace
Cuemon.Extensions.AspNetCore.Text.Json.Formatters
Assembly
Cuemon.Extensions.AspNetCore.Text.Json.dll

Extension methods for the IServiceCollection interface.

public static class ServiceCollectionExtensions
Inheritance
ServiceCollectionExtensions

Examples

The following example demonstrates how to register JSON formatter options and a JSON-based exception response formatter in the ASP.NET Core service collection.

using Cuemon.Extensions.AspNetCore.Text.Json.Formatters;
using Microsoft.Extensions.DependencyInjection;

namespace MyApp.Examples;

public class JsonFormattersServiceCollectionExtensionsExample
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddJsonFormatterOptions(options =>
        {
            options.SensitivityDetails = Cuemon.Diagnostics.FaultSensitivityDetails.All;
        });

        services.AddJsonExceptionResponseFormatter();

}
}

Methods

AddJsonExceptionResponseFormatter(IServiceCollection, Action<JsonFormatterOptions>)

Adds an IHttpExceptionDescriptorResponseFormatter that uses JsonFormatter as engine of serialization to the specified list of services.

public static IServiceCollection AddJsonExceptionResponseFormatter(this IServiceCollection services, Action<JsonFormatterOptions> setup = null)

Parameters

services IServiceCollection

The IServiceCollection to extend.

setup Action<JsonFormatterOptions>

The JsonFormatterOptions which may be configured.

Returns

IServiceCollection

A reference to services so that additional calls can be chained.

Remarks

Configuration of the JsonFormatter is done through a call to GetService<T>(IServiceProvider) retrieving an IOptions<TOptions> implementation of JsonFormatterOptions.

Exceptions

ArgumentNullException

services cannot be null

AddJsonFormatterOptions(IServiceCollection, Action<JsonFormatterOptions>)

Adds configuration of JsonFormatterOptions for the application.

public static IServiceCollection AddJsonFormatterOptions(this IServiceCollection services, Action<JsonFormatterOptions> setup = null)

Parameters

services IServiceCollection

The IServiceCollection to extend.

setup Action<JsonFormatterOptions>

The JsonFormatterOptions which may be configured.

Returns

IServiceCollection

A reference to services so that additional configuration calls can be chained.

Exceptions

ArgumentNullException

services cannot be null.

ArgumentException

setup failed to configure an instance of JsonFormatterOptions in a valid state.