using NCC.Dependency; using NCC.JsonSerialization; using Microsoft.AspNetCore.Mvc; using System; namespace Microsoft.Extensions.DependencyInjection { /// /// Json 序列化服务拓展类 /// [SuppressSniffer] public static class JsonSerializationServiceCollectionExtensions { /// /// 配置 Json 序列化提供器 /// /// /// /// public static IServiceCollection AddJsonSerialization(this IServiceCollection services) where TJsonSerializerProvider : class, IJsonSerializerProvider { services.AddSingleton(); return services; } /// /// 配置 JsonOptions 序列化选项 /// 主要给非 Web 环境使用 /// /// /// /// public static IServiceCollection AddJsonOptions(this IServiceCollection services, Action configure) { // 手动添加配置 services.Configure(options => { configure?.Invoke(options); }); return services; } } }