/// <summary> /// Add SnowLeopard Mvc /// </summary> /// <param name="services"></param> public static IMvcBuilder AddSnowLeopardMvc(this IServiceCollection services) { return(services .AddMvc(options => { options.AddSnowLeopardFilters(); }) .AddControllersAsServices() .AddJsonOptions(options =>// 全局配置Json序列化处理 { JsonSerializerSetting.InitJsonSerializerSetting(options.SerializerSettings); })); }
/// <summary> /// AddSnowLeopardMongoContext /// </summary> /// <param name="services"></param> public static void AddSnowLeopardMongoContext(this IServiceCollection services) { JsonSerializerSetting.Config(x => { x.Converters.Add(new ObjectIdConverter()); }); var types = LynxUtils.GetAllType(); var singletonServiceInterface = typeof(MongoContext); var singletonServiceTypes = types.Where(x => singletonServiceInterface.IsAssignableFrom(x) && !x.GetTypeInfo().IsAbstract).ToArray(); // 注册 Singleton 服务 foreach (var serviceType in singletonServiceTypes) { services.TryAddSingleton(serviceType); } }