Overview
Cuemon.Extensions.AspNetCore.Mvc.Formatters.Xml plugs Cuemon's XmlFormatter into the ASP.NET Core MVC formatter pipeline. It extends Cuemon.Extensions.AspNetCore.Xml with IMvcBuilder and IMvcCoreBuilder registration methods plus concrete MVC input and output formatters, so controller endpoints can read and write XML through the same XmlFormatterOptions model.
The package keeps the MVC integration small and explicit. XmlSerializationMvcOptionsSetup inserts the Cuemon formatters at the front of MvcOptions, while the formatter constructors add the configured media types and register the HTTP exception descriptor converter that mirrors SensitivityDetails into XML exception serialization.
Key APIs
MvcBuilderExtensions.AddXmlFormatters registers XmlSerializationMvcOptionsSetup for the MVC builder and then applies the package's XML formatter options path, which makes it the main entry point for AddControllers() scenarios.
MvcBuilderExtensions.AddXmlFormattersOptions configures XmlFormatterOptions through the lower-level ASP.NET Core XML package without inserting MVC formatter instances on its own.
MvcCoreBuilderExtensions.AddXmlFormatters gives the same formatter registration behavior to AddMvcCore() pipelines, which is the registration path used in the package's controller integration tests.
MvcCoreBuilderExtensions.AddXmlFormattersOptions exposes the options-only path for IMvcCoreBuilder, so a core MVC setup can share the same XmlFormatterOptions configuration model.
XmlSerializationInputFormatter deserializes request bodies with XmlFormatter; the tests verify UTF-8 and UTF-16 encodings, and the constructor copies the configured XML media types into MVC's supported media type collection.
XmlSerializationOutputFormatter mirrors that setup for responses, using the same formatter options and media types while adding the XML HTTP exception descriptor converter to the underlying formatter settings.
XmlSerializationMvcOptionsSetup is the ConfigureOptions<MvcOptions> implementation that inserts the output formatter first and the input formatter second, so Cuemon's XML formatters are considered before later MVC registrations.
Basic usage
using System.Linq;
using Codebelt.Extensions.Xunit;
using Cuemon.Extensions.AspNetCore.Mvc.Formatters.Xml;
using Cuemon.Xml.Serialization.Formatters;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Xunit;
namespace MyProject.Tests;
public class XmlFormatterRegistrationTest : Test
{
public XmlFormatterRegistrationTest(ITestOutputHelper output) : base(output)
{
}
[Fact]
public void AddXmlFormatters_ShouldRegisterCuemonMvcFormatters()
{
var services = new ServiceCollection();
services.AddControllers().AddXmlFormatters();
using var provider = services.BuildServiceProvider();
var formatterOptions = provider.GetRequiredService<IOptions<XmlFormatterOptions>>().Value;
var mvcOptions = provider.GetRequiredService<IOptions<MvcOptions>>().Value;
var inputMediaTypes = Assert.IsType<XmlSerializationInputFormatter>(mvcOptions.InputFormatters[0]).SupportedMediaTypes.Select(mediaType => mediaType.ToString()).ToArray();
var outputMediaTypes = Assert.IsType<XmlSerializationOutputFormatter>(mvcOptions.OutputFormatters[0]).SupportedMediaTypes.Select(mediaType => mediaType.ToString()).ToArray();
Assert.NotNull(formatterOptions.Settings);
Assert.Contains("application/xml", inputMediaTypes);
Assert.Contains("application/problem+xml", outputMediaTypes);
TestOutput.WriteLine(string.Join(", ", outputMediaTypes));
}
}
Use this pattern when controller registration should move Cuemon XML formatting into MVC in the same place you add controllers. It matters because the package inserts its request and response formatters first, so MVC uses the same XmlFormatterOptions configuration for request bodies, responses, and XML problem details.
Installation
dotnet add package Cuemon.Extensions.AspNetCore.Mvc.Formatters.Xml
Usage guidance
Adopt this package when an ASP.NET Core MVC application should negotiate XML through Cuemon's formatter stack and keep formatter registration aligned with XmlFormatterOptions. If you only need lower-level XML formatter configuration outside MVC, or the built-in ASP.NET Core XML formatter behavior is sufficient, use Cuemon.Extensions.AspNetCore.Xml, Cuemon.Extensions.Xml, or plain framework registration instead.
Family packages
- 🌐Cuemon.AspNetCore
- 🏭Cuemon.AspNetCore.App
- 🌐Cuemon.AspNetCore.Authentication
- 🌐Cuemon.AspNetCore.Mvc
- 🌐Cuemon.AspNetCore.Razor.TagHelpers
- 📦Cuemon.Core
- 🏭Cuemon.Core.App
- 🗄️Cuemon.Data
- 🗄️Cuemon.Data.Integrity
- 🗄️Cuemon.Data.SqlClient
- 🩺Cuemon.Diagnostics
- 🌐Cuemon.Extensions.AspNetCore
- 🌐Cuemon.Extensions.AspNetCore.Authentication
- 🌐Cuemon.Extensions.AspNetCore.Mvc
- 🌐Cuemon.Extensions.AspNetCore.Mvc.Formatters.Text.Json
- 🌐Cuemon.Extensions.AspNetCore.Mvc.RazorPages
- 🌐Cuemon.Extensions.AspNetCore.Text.Json
- 🌐Cuemon.Extensions.AspNetCore.Xml
- 📦Cuemon.Extensions.Collections.Generic
- 📦Cuemon.Extensions.Collections.Specialized
- 📦Cuemon.Extensions.Core
- 🗄️Cuemon.Extensions.Data
- 🗄️Cuemon.Extensions.Data.Integrity
- 📦Cuemon.Extensions.DependencyInjection
- 🩺Cuemon.Extensions.Diagnostics
- 🏗️Cuemon.Extensions.Hosting
- 📦Cuemon.Extensions.IO
- 📦Cuemon.Extensions.Net
- 📦Cuemon.Extensions.Reflection
- 📦Cuemon.Extensions.Runtime.Caching
- 📝Cuemon.Extensions.Text
- 📝Cuemon.Extensions.Text.Json
- 📦Cuemon.Extensions.Threading
- 📦Cuemon.Extensions.Xml
- 📦Cuemon.IO
- ⚙️Cuemon.Kernel
- 📦Cuemon.Net
- 📦Cuemon.Resilience
- 📦Cuemon.Runtime.Caching
- 🔐Cuemon.Security.Cryptography
- 📦Cuemon.Threading
- 📦Cuemon.Xml