Table of Contents

Class ServiceCollectionExtensions

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

Extension methods for the IServiceCollection interface.

public static class ServiceCollectionExtensions
Inheritance
ServiceCollectionExtensions

Examples

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

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

namespace MyApp.Examples;

public class XmlFormattersServiceCollectionExtensionsExample
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddXmlFormatterOptions(options =>
        {
            options.SynchronizeWithXmlConvert = true;
        });

        services.AddXmlExceptionResponseFormatter();

}
}

Methods

AddXmlExceptionResponseFormatter(IServiceCollection, Action<XmlFormatterOptions>)

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

public static IServiceCollection AddXmlExceptionResponseFormatter(this IServiceCollection services, Action<XmlFormatterOptions> setup = null)

Parameters

services IServiceCollection

The IServiceCollection to extend.

setup Action<XmlFormatterOptions>

The XmlFormatterOptions which may be configured.

Returns

IServiceCollection

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

Remarks

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

Exceptions

ArgumentNullException

services cannot be null

AddXmlFormatterOptions(IServiceCollection, Action<XmlFormatterOptions>)

Adds configuration of XmlFormatterOptions for the application.

public static IServiceCollection AddXmlFormatterOptions(this IServiceCollection services, Action<XmlFormatterOptions> setup = null)

Parameters

services IServiceCollection

The IServiceCollection to extend.

setup Action<XmlFormatterOptions>

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