/// <summary> /// 初始化,必须先调用 /// </summary> public static void InitializeBase(bool bear) { if (IsInitialize) { return; } IocHelper.Update(); IocHelper.AddScoped <GlobalContext, BusinessContext>(); IocHelper.AddSingleton <IZeroPublisher, ZeroNetBridge>(); IocHelper.AddSingleton <IGlobalContext, BusinessContext>(p => BusinessContext.Context); IocHelper.Update(); Environment.CurrentDirectory = ConfigurationManager.BasePath = HttpContext.Current.Server.MapPath("~"); LogRecorder.Initialize(); LogRecorder.SystemLog("启动"); LogRecorder.GetRequestIdFunc = () => RandomOperate.Generate(8); GlobalConfiguration.Configuration.MapHttpAttributeRoutes(new CustomDirectRouteProvider()); HttpHandler.Handlers.Add(new CorsHandler()); HttpHandler.Handlers.Add(new HttpIoLogHandler()); if (bear) { HttpHandler.Handlers.Add(new BearerHandler()); } IsInitialize = true; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc(); IocHelper.AddSingleton <PlanManage>(); ZeroApplication.RegistZeroObject <ApiCounter>(); ZeroApplication.RegistZeroObject <PlanSubscribe>(); ZeroApplication.RegistZeroObject <EventSub>(); ZeroApplication.Initialize(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); //.AddJsonOptions(options => // { // //忽略循环引用 // options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // //不使用驼峰样式的key // options.SerializerSettings.ContractResolver = new DefaultContractResolver(); // //设置时间格式 // options.SerializerSettings.DateFormatString = "yyyy-MM-dd"; // }); }
/// <summary> /// 初始化 /// </summary> public static void Initialize() { IocHelper.AddSingleton <IZeroPublisher, ZeroPublisher>(); ConsumerConfig config = ConfigurationManager.Get <ConsumerConfig>("Kafka"); producer = new ProducerBuilder <Null, string>(new ProducerConfig { BootstrapServers = config.BootstrapServers }).Build(); }
/// <summary> /// 初始化 /// </summary> void IAutoRegister.Initialize() { //services.AddOptions(); //services.Configure<HisOptions>(Configuration.GetSection(nameof(HisOptions))); IocHelper.AddSingleton <IFoo, Foo>(); IocHelper.AddSingleton <IFoo, FooEx>(); //IocHelper.AddSingleton<HisOptions>(Agebull.Common.Configuration.ConfigurationManager.SetConfiguration(nameof(HisOptions))); }
/// <summary> /// /// </summary> public void Initialize() { IocHelper.AddSingleton <ITestService, TestService>(); }