using NCC.Dependency; using NCC.SensitiveDetection; using System; namespace Microsoft.Extensions.DependencyInjection { /// /// 脱敏词汇处理服务 /// [SuppressSniffer] public static class SensitiveDetectionServiceCollectionExtensions { /// /// 添加脱敏词汇服务 /// 需要在入口程序集目录下创建 sensitive-words.txt /// /// /// public static IMvcBuilder AddSensitiveDetection(this IMvcBuilder mvcBuilder) { var services = mvcBuilder.Services; services.AddSensitiveDetection(); return mvcBuilder; } /// /// 添加脱敏词汇服务 /// /// /// /// /// public static IMvcBuilder AddSensitiveDetection(this IMvcBuilder mvcBuilder, Action handle = default) where TSensitiveDetectionProvider : class, ISensitiveDetectionProvider { var services = mvcBuilder.Services; // 注册脱敏词汇服务 services.AddSensitiveDetection(handle); return mvcBuilder; } /// /// 添加脱敏词汇服务 /// 需要在入口程序集目录下创建 sensitive-words.txt /// /// /// public static IServiceCollection AddSensitiveDetection(this IServiceCollection services) { return services.AddSensitiveDetection(); } /// /// 添加脱敏词汇服务 /// /// /// /// /// public static IServiceCollection AddSensitiveDetection(this IServiceCollection services, Action handle = default) where TSensitiveDetectionProvider : class, ISensitiveDetectionProvider { // 注册脱敏词汇服务 services.AddSingleton(); // 自定义配置 handle?.Invoke(services); return services; } } }