Table of Contents

Class MvcCoreBuilderExtensions

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

Extension methods for the IMvcCoreBuilder interface.

public static class MvcCoreBuilderExtensions
Inheritance
MvcCoreBuilderExtensions

Examples

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

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

namespace DocfxExamples;

public class MvcCoreBuilderExtensionsExample
{
    public void ConfigureMvc(IMvcCoreBuilder builder)
    {
        // Invoke the AddJsonFormatters extension method
        MvcCoreBuilderExtensions.AddJsonFormatters(builder, options =>
        {
            options.Settings.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
            options.Settings.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
        });

        // Invoke the AddJsonFormattersOptions extension method
        MvcCoreBuilderExtensions.AddJsonFormattersOptions(builder, options =>
        {
            options.Settings.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
        });

}
}

Methods

AddJsonFormatters(IMvcCoreBuilder, Action<JsonFormatterOptions>)

Adds the JSON serializer formatters to MVC.

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

Parameters

builder IMvcCoreBuilder

The IMvcCoreBuilder.

setup Action<JsonFormatterOptions>

The JsonFormatterOptions which may be configured.

Returns

IMvcCoreBuilder

A reference to builder after the operation has completed.

Exceptions

ArgumentNullException

builder cannot be null.

AddJsonFormattersOptions(IMvcCoreBuilder, Action<JsonFormatterOptions>)

Adds configuration of JsonFormatterOptions for the application.

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

Parameters

builder IMvcCoreBuilder

The IMvcBuilder.

setup Action<JsonFormatterOptions>

The JsonFormatterOptions which need to be configured.

Returns

IMvcCoreBuilder

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.