Table of Contents

MvcCoreBuilderExtensions Class

Definition

Namespace
Codebelt.Extensions.AspNetCore.Mvc.Formatters.Text.Yaml
Assemblies
Codebelt.Extensions.AspNetCore.Mvc.Formatters.Text.Yaml.dll
Source
src/Codebelt.Extensions.AspNetCore.Mvc.Formatters.Text.Yaml/MvcCoreBuilderExtensions.cs

Extension methods for the IMvcCoreBuilder interface.

public static class MvcCoreBuilderExtensions
Inheritance
MvcCoreBuilderExtensions

Examples

This example configures ASP.NET Core's lightweight MVC core builder with YAML input and output formatters using the builder extension pattern. It shows how to register formatters during startup when using AddMvcCore() for minimal APIs or custom configurations, including custom sensitivity settings to control exception serialization detail levels. The example demonstrates both the fluent AddYamlFormatters method (with inline options) and the separate AddYamlFormattersOptions method, illustrating the setup workflow and how both approaches integrate with the container and request/response pipeline.

using Codebelt.Extensions.AspNetCore.Mvc.Formatters.Text.Yaml;
using Codebelt.Extensions.YamlDotNet.Formatters;
using Cuemon.Diagnostics;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;

namespace ExampleNamespace;

class Program
{
    static void Main()
    {
        var builder = WebApplication.CreateBuilder();
        
        // Add MVC core services with YAML formatters
        var mvcCoreBuilder = builder.Services.AddMvcCore()
            .AddYamlFormatters(options =>
            {
                options.SensitivityDetails = FaultSensitivityDetails.StackTrace | FaultSensitivityDetails.Data;
            });
        
        // Or configure options separately with required parameter
        builder.Services.AddMvcCore()
            .AddYamlFormattersOptions(options =>
            {
                options.SensitivityDetails = FaultSensitivityDetails.All;
            });
        
        var app = builder.Build();
        
        app.MapControllers();
        
        app.Run();
    }
}

Methods

Name Description
AddYamlFormatters(IMvcCoreBuilder, Action<YamlFormatterOptions>)

Adds the YAML serializer formatters to MVC.

AddYamlFormattersOptions(IMvcCoreBuilder, Action<YamlFormatterOptions>)

Adds configuration of YamlFormatterOptions for the application.