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
servicesIServiceCollectionThe IServiceCollection to extend.
setupAction<XmlFormatterOptions>The XmlFormatterOptions which may be configured.
Returns
- IServiceCollection
A reference to
servicesso 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
servicescannot 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
servicesIServiceCollectionThe IServiceCollection to extend.
setupAction<XmlFormatterOptions>The XmlFormatterOptions which may be configured.
Returns
- IServiceCollection
A reference to
servicesso that additional configuration calls can be chained.
Exceptions
- ArgumentNullException
servicescannot be null.- ArgumentException
setupfailed to configure an instance of XmlFormatterOptions in a valid state.