Ejemplo n.º 1
0
        /// <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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 重载
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            IocHelper.Update();
            foreach (IHttpSystemHandler handler in Handlers)
            {
                try
                {
                    Task <HttpResponseMessage> task = handler.OnBegin(request, cancellationToken);
                    if (task != null)
                    {
                        return(DoEnd(task, request, cancellationToken));
                    }
                }
                catch (Exception ex)
                {
                    LogRecorder.Exception(ex);
                }
            }
            Task <HttpResponseMessage> t = base.SendAsync(request, cancellationToken);

            return(DoEnd(t, request, cancellationToken));
        }