Table of Contents

Class MvcBuilderExtensions

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

Extension methods for the IMvcBuilder interface.

public static class MvcBuilderExtensions
Inheritance
MvcBuilderExtensions

Examples

The following example demonstrates how to register JSON serialization formatters on an using the extension methods.

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

namespace DocfxExamples;

public class MvcBuilderExtensionsExample
{
    public void ConfigureMvc(IMvcBuilder builder)
    {
        // Invoke the AddJsonFormatters extension method
        MvcBuilderExtensions.AddJsonFormatters(builder, options =>
        {
            options.SensitivityDetails = FaultSensitivityDetails.All;
            options.Settings.WriteIndented = true;
        });

        // Invoke the AddJsonFormattersOptions extension method
        MvcBuilderExtensions.AddJsonFormattersOptions(builder, options =>
        {
            options.Settings.WriteIndented = true;
        });

}
}

Methods

AddJsonFormatters(IMvcBuilder, Action<JsonFormatterOptions>)

Adds the JSON serializer formatters to MVC.

public static IMvcBuilder AddJsonFormatters(this IMvcBuilder builder, Action<JsonFormatterOptions> setup = null)

Parameters

builder IMvcBuilder

The IMvcBuilder.

setup Action<JsonFormatterOptions>

The JsonFormatterOptions which may be configured.

Returns

IMvcBuilder

A reference to builder after the operation has completed.

Exceptions

ArgumentNullException

builder cannot be null -or- setup cannot be null.

AddJsonFormattersOptions(IMvcBuilder, Action<JsonFormatterOptions>)

Adds configuration of JsonFormatterOptions for the application.

public static IMvcBuilder AddJsonFormattersOptions(this IMvcBuilder builder, Action<JsonFormatterOptions> setup = null)

Parameters

builder IMvcBuilder

The IMvcBuilder.

setup Action<JsonFormatterOptions>

The JsonFormatterOptions which need to be configured.

Returns

IMvcBuilder

A reference to builder after the operation has completed.

Exceptions

ArgumentNullException

builder cannot be null.

ArgumentException

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