Table of Contents

ServiceCollectionExtensions Class

Definition

Extension methods for the IServiceCollection interface.

public static class ServiceCollectionExtensions
Inheritance
ServiceCollectionExtensions

Examples

Register NewtonsoftJsonMarshaller in the DI container with AddNewtonsoftJsonMarshaller.

using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Savvyio.Extensions.DependencyInjection.Newtonsoft.Json;

namespace ExampleApp;

public static class JsonDependencyInjectionSetup
{
    public static IServiceCollection AddNewtonsoftSerialization(this IServiceCollection services)
    {
        services.AddNewtonsoftJsonMarshaller(options =>
        {
            options.Settings.Formatting = Formatting.Indented;
            options.Settings.NullValueHandling = NullValueHandling.Ignore;
        });

        return services;
    }
}

Methods

Name Description
AddNewtonsoftJsonMarshaller(IServiceCollection, Action<NewtonsoftJsonFormatterOptions>, Action<ServiceOptions>)

Adds an NewtonsoftJsonMarshaller implementation to the specified IServiceCollection.