private static HttpMessageHandlerOptions CreateHttpMesageHandlerOptions()
        {
            var config = new HttpConfiguration();


            config.Services.Replace(typeof(IExceptionHandler), new WebApi.V2.ApiExceptionHandler());
            config.Services.Replace(typeof(IHttpControllerSelector), new ServiceUnitApiControllerSelector(config));
            config.Services.Replace(typeof(IHttpControllerActivator), new ServiceUnitApiControllerActivator(config));
            //authorize
            config.Services.Replace(typeof(IHttpActionSelector), new ServiceUnitApiActionSelector(config));

            config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling  = DateTimeZoneHandling.Utc;


            HttpServer        httpServer = new HttpServer(config, new ServiceUnitRequestDispatcher(config));
            ServicesContainer services   = config.Services;

            return(new HttpMessageHandlerOptions()
            {
                MessageHandler = httpServer,
                BufferPolicySelector = services.GetHostBufferPolicySelector() ?? new OwinBufferPolicySelector(),
                ExceptionLogger = ExceptionServices.GetLogger(services),
                ExceptionHandler = ExceptionServices.GetHandler(services),
            });
        }
Example #2
0
        private static HttpMessageHandlerOptions CreateOptions(
            IAppBuilder builder,
            HttpServer server,
            HttpConfiguration configuration
            )
        {
            Contract.Assert(builder != null);
            Contract.Assert(server != null);
            Contract.Assert(configuration != null);

            ServicesContainer services = configuration.Services;

            Contract.Assert(services != null);

            IHostBufferPolicySelector bufferPolicySelector =
                services.GetHostBufferPolicySelector() ?? _defaultBufferPolicySelector;
            IExceptionLogger  exceptionLogger  = ExceptionServices.GetLogger(services);
            IExceptionHandler exceptionHandler = ExceptionServices.GetHandler(services);

            return(new HttpMessageHandlerOptions
            {
                MessageHandler = server,
                BufferPolicySelector = bufferPolicySelector,
                ExceptionLogger = exceptionLogger,
                ExceptionHandler = exceptionHandler,
                AppDisposing = builder.GetOnAppDisposingProperty()
            });
        }
        private static HttpMessageHandlerOptions CreateOptions(IApplicationBuilder builder, HttpServer server,
                                                               HttpConfiguration configuration, bool bufferRequests)
        {
            Contract.Assert(builder != null);
            Contract.Assert(server != null);
            Contract.Assert(configuration != null);

            ServicesContainer services = configuration.Services;

            Contract.Assert(services != null);

            IHostBufferPolicySelector bufferPolicySelector = services.GetHostBufferPolicySelector()
                                                             ?? new AspNetCoreBufferPolicySelector(bufferRequests);
            IExceptionLogger  exceptionLogger  = ExceptionServices.GetLogger(services);
            IExceptionHandler exceptionHandler = ExceptionServices.GetHandler(services);

            return(new HttpMessageHandlerOptions
            {
                MessageHandler = server,
                BufferPolicySelector = bufferPolicySelector,
                ExceptionLogger = exceptionLogger,
                ExceptionHandler = exceptionHandler,
            });
        }