Table of Contents

Class MvcBuilderExtensions

Namespace
Cuemon.Extensions.AspNetCore.Mvc.Formatters.Xml
Assembly
Cuemon.Extensions.AspNetCore.Mvc.Formatters.Xml.dll

Extension methods for the IMvcBuilder interface.

public static class MvcBuilderExtensions
Inheritance
MvcBuilderExtensions

Examples

The following example demonstrates how to add XML serialization formatters to an MVC builder. It calls AddXmlFormatters with indentation enabled, then AddXmlFormattersOptions with indentation disabled, on the builder returned by AddControllers. Both calls configure the underlying XmlWriter settings, showing how to register and customize XML input/output formatters for ASP.NET Core API controllers.

using Cuemon.Extensions.AspNetCore.Mvc.Formatters.Xml;
using Microsoft.Extensions.DependencyInjection;

namespace MyApp.Examples
{
    public static class MvcBuilderExtensionsExample
    {
        public static void ConfigureServices(IServiceCollection services)
        {
            var builder = services.AddControllers();

            builder.AddXmlFormatters(options =>
            {
                options.Settings.Writer.Indent = true;
            });

            builder.AddXmlFormattersOptions(options =>
            {
                options.Settings.Writer.Indent = false;
            });
        }
    }
}

Methods

AddXmlFormatters(IMvcBuilder, Action<XmlFormatterOptions>)

Adds the XML serializer formatters to MVC.

public static IMvcBuilder AddXmlFormatters(this IMvcBuilder builder, Action<XmlFormatterOptions> setup = null)

Parameters

builder IMvcBuilder

The IMvcBuilder to extend.

setup Action<XmlFormatterOptions>

The XmlFormatterOptions 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.

AddXmlFormattersOptions(IMvcBuilder, Action<XmlFormatterOptions>)

Adds configuration of XmlFormatterOptions for the application.

public static IMvcBuilder AddXmlFormattersOptions(this IMvcBuilder builder, Action<XmlFormatterOptions> setup = null)

Parameters

builder IMvcBuilder

The IMvcBuilder to extend.

setup Action<XmlFormatterOptions>

The XmlFormatterOptions 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 XmlFormatterOptions in a valid state.