Example #1
0
    public static void ConfigureWebApi(HttpConfiguration httpConfiguration, EntityApp app, 
                             LogLevel logLevel = LogLevel.Basic,
                             WebHandlerOptions webHandlerOptions = WebHandlerOptions.DefaultDebug) {
      // Logging message handler
      var webHandlerStt = new WebCallContextHandlerSettings(logLevel, webHandlerOptions);
      var webContextHandler = new WebCallContextHandler(app, webHandlerStt);
      httpConfiguration.MessageHandlers.Add(webContextHandler);

      // Exception handling filter - to handle/save exceptions
      httpConfiguration.Filters.Add(new ExceptionHandlingFilter());

      // Formatters - add formatters with spies, to catch/log deserialization failures
      httpConfiguration.Formatters.Clear();
      httpConfiguration.Formatters.Add(new StreamMediaTypeFormatter("image/jpeg", "image/webp")); //webp is for Chrome
      var xmlFmter = new XmlMediaTypeFormatter();
      httpConfiguration.Formatters.Add(xmlFmter);
      var jsonFmter = new JsonMediaTypeFormatter();
      // add converter that will serialize all enums as strings, not integers
      jsonFmter.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
      var resolver = jsonFmter.SerializerSettings.ContractResolver = new JsonContractResolver(jsonFmter);
      httpConfiguration.Formatters.Add(jsonFmter);

      //Api configuration
      if (app.ApiConfiguration.ControllerInfos.Count > 0)
        ConfigureSlimApi(httpConfiguration, app);
    }
Example #2
0
        public static void ConfigureWebApi(HttpConfiguration httpConfiguration, EntityApp app,
                                           LogLevel logLevel = LogLevel.Basic,
                                           WebHandlerOptions webHandlerOptions = WebHandlerOptions.DefaultDebug,
                                           ApiNameMapping nameMapping          = ApiNameMapping.Default)
        {
            // Logging message handler
            var webHandlerStt     = new WebCallContextHandlerSettings(logLevel, webHandlerOptions);
            var webContextHandler = new WebCallContextHandler(app, webHandlerStt);

            httpConfiguration.MessageHandlers.Add(webContextHandler);

            // Exception handling filter - to handle/save exceptions
            httpConfiguration.Filters.Add(new ExceptionHandlingFilter());

            // Formatters - add formatters with spies, to catch/log deserialization failures
            httpConfiguration.Formatters.Clear();
            httpConfiguration.Formatters.Add(new StreamMediaTypeFormatter("image/jpeg", "image/webp")); //webp is for Chrome
            var xmlFmter = new XmlMediaTypeFormatter();

            httpConfiguration.Formatters.Add(xmlFmter);
            var jsonFmter = new JsonMediaTypeFormatter();

            // add converter that will serialize all enums as strings, not integers
            jsonFmter.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
            jsonFmter.SerializerSettings.ContractResolver     = new JsonNameContractResolver(nameMapping);
            jsonFmter.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Unspecified;
            httpConfiguration.Formatters.Add(jsonFmter);

            //Api configuration
            if (app.ApiConfiguration.ControllerInfos.Count > 0)
            {
                ConfigureSlimApiControllers(httpConfiguration, app);
            }

            app.RegisterService <IBackgroundTaskService>(new WebBackgroundTaskService(app));
        }