Table of Contents

ServiceCollectionExtensions Class

Definition

Namespace
Savvyio.Extensions.DependencyInjection.Text.Json
Assemblies
Savvyio.Extensions.DependencyInjection.Text.Json.dll
Source
src/Savvyio.Extensions.DependencyInjection.Text.Json/ServiceCollectionExtensions.cs

Extension methods for the IServiceCollection interface.

public static class ServiceCollectionExtensions
Inheritance
object
ServiceCollectionExtensions

Examples

Register JsonMarshaller in the DI container with AddJsonMarshaller.

using System.Text.Json;
using Microsoft.Extensions.DependencyInjection;
using Savvyio.Extensions.DependencyInjection.Text.Json;

namespace ExampleApp;

public static class JsonDependencyInjectionSetup
{
    public static IServiceCollection AddSystemTextJsonSerialization(this IServiceCollection services)
    {
        services.AddJsonMarshaller(options =>
        {
            options.Settings.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
            options.Settings.WriteIndented = true;
        });

        return services;
    }
}

Methods

Name Description
AddJsonMarshaller(IServiceCollection, Action<JsonFormatterOptions>, Action<ServiceOptions>)

Adds an JsonMarshaller implementation to the specified IServiceCollection.