Table of Contents

Class MvcBuilderExtensions

Namespace
Codebelt.Extensions.AspNetCore.Mvc.Formatters.Text.Yaml
Assembly
Codebelt.Extensions.AspNetCore.Mvc.Formatters.Text.Yaml.dll

Extension methods for the IMvcBuilder interface.

public static class MvcBuilderExtensions
Inheritance
MvcBuilderExtensions

Examples

This example configures ASP.NET Core's MVC builder with YAML input and output formatters using the builder extension pattern. It shows how to register formatters during startup with custom sensitivity settings that control whether stack traces, data, or evidence are included in serialized exceptions. The example demonstrates both the fluent AddYamlFormatters method (with inline options) and the separate AddYamlFormattersOptions method, illustrating how to build the host and configure the container for YAML request/response handling in MVC applications.

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 with YAML formatters
        builder.Services.AddControllersWithViews()
            .AddYamlFormatters(options =>
            {
                options.SensitivityDetails = FaultSensitivityDetails.StackTrace | FaultSensitivityDetails.Data;
            });
        
        // Or configure options separately
        builder.Services.AddControllersWithViews()
            .AddYamlFormattersOptions(options =>
            {
                options.SensitivityDetails = FaultSensitivityDetails.All;
            });
        
        var app = builder.Build();
        
        app.MapControllers();
        
        app.Run();
    }
}

Methods

AddYamlFormatters(IMvcBuilder, Action<YamlFormatterOptions>)

Adds the YAML serializer formatters to MVC.

public static IMvcBuilder AddYamlFormatters(this IMvcBuilder builder, Action<YamlFormatterOptions> setup = null)

Parameters

builder IMvcBuilder

The IMvcBuilder.

setup Action<YamlFormatterOptions>

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

AddYamlFormattersOptions(IMvcBuilder, Action<YamlFormatterOptions>)

Adds configuration of YamlFormatterOptions for the application.

public static IMvcBuilder AddYamlFormattersOptions(this IMvcBuilder builder, Action<YamlFormatterOptions> setup = null)

Parameters

builder IMvcBuilder

The IMvcBuilder.

setup Action<YamlFormatterOptions>

The YamlFormatterOptions which need to be configured.

Returns

IMvcBuilder

A reference to builder after the operation has completed.

Exceptions

ArgumentNullException

builder cannot be null.