Documentation Coverage Report
Current view: top level - Cqrs.WebApi/Configuration - WebApiConfig.cs Hit Total Coverage
Version: 2.2 Artefacts: 2 2 100.0 %
Date: 2017-09-22

          Line data    Source code
       1             : #region Copyright
       2             : // // -----------------------------------------------------------------------
       3             : // // <copyright company="Chinchilla Software Limited">
       4             : // //   Copyright Chinchilla Software Limited. All rights reserved.
       5             : // // </copyright>
       6             : // // -----------------------------------------------------------------------
       7             : #endregion
       8             : 
       9             : using System;
      10             : using System.Web.Http;
      11             : using System.Web.Http.Cors;
      12             : using Cqrs.Configuration;
      13             : using Newtonsoft.Json;
      14             : 
      15             : namespace Cqrs.WebApi.Configuration
      16             : {
      17             :         /// <summary>
      18             :         /// A configuration class for WebAPI.
      19             :         /// </summary>
      20             :         public class WebApiConfig
      21           1 :         {
      22             :                 /// <summary>
      23             :                 /// Registers the require routes, set relevant CORS settings and defines WebAPI relevant JSON serialisation settings.
      24             :                 /// </summary>
      25           1 :                 public static void Register(HttpConfiguration config)
      26             :                 {
      27             :                         var configurationManager = DependencyResolver.Current.Resolve<IConfigurationManager>();
      28             :                         var cors = new EnableCorsAttribute
      29             :                         (
      30             :                                 configurationManager.GetSetting("Cqrs.WebApi.Cors.Origins"),
      31             :                                 configurationManager.GetSetting("Cqrs.WebApi.Cors.Headers"),
      32             :                                 configurationManager.GetSetting("Cqrs.WebApi.Cors.Methods"),
      33             :                                 configurationManager.GetSetting("Cqrs.WebApi.Cors.ExposedHeaders")
      34             :                         );
      35             :                         config.EnableCors(cors);
      36             : 
      37             :                         try
      38             :                         {
      39             :                                 config.MapHttpAttributeRoutes();
      40             :                         }
      41             :                         catch (ArgumentException exception)
      42             :                         {
      43             :                                 if (exception.ParamName != "name")
      44             :                                         throw;
      45             :                         }
      46             : 
      47             :                         GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
      48             :                         {
      49             :                                 ContractResolver = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.ContractResolver,
      50             :                                 StringEscapeHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.StringEscapeHandling,
      51             :                                 PreserveReferencesHandling = PreserveReferencesHandling.None,
      52             :                                 MissingMemberHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.MissingMemberHandling,
      53             :                                 Binder = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.Binder,
      54             :                                 CheckAdditionalContent = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.CheckAdditionalContent,
      55             :                                 ConstructorHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.ConstructorHandling,
      56             :                                 Context = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.Context,
      57             :                                 Converters = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.Converters,
      58             :                                 Culture = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.Culture,
      59             :                                 DateFormatHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.DateFormatHandling,
      60             :                                 DateFormatString = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.DateFormatString,
      61             :                                 DateParseHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.DateParseHandling,
      62             :                                 DateTimeZoneHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.DateTimeZoneHandling,
      63             :                                 DefaultValueHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.DefaultValueHandling,
      64             :                                 Error = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.Error,
      65             :                                 FloatFormatHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.FloatFormatHandling,
      66             :                                 FloatParseHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.FloatParseHandling,
      67             :                                 Formatting = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.Formatting,
      68             :                                 MaxDepth = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.MaxDepth,
      69             :                                 MetadataPropertyHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.MetadataPropertyHandling,
      70             :                                 NullValueHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.NullValueHandling,
      71             :                                 ObjectCreationHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.ObjectCreationHandling,
      72             :                                 ReferenceLoopHandling = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.ReferenceLoopHandling,
      73             :                                 ReferenceResolver = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.ReferenceResolver,
      74             :                                 TraceWriter = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.TraceWriter,
      75             :                                 TypeNameAssemblyFormat = Cqrs.Events.DefaultJsonSerializerSettings.DefaultSettings.TypeNameAssemblyFormat,
      76             :                                 TypeNameHandling = TypeNameHandling.None
      77             :                         };
      78             :                 }
      79             :         }
      80             : }

Generated by: LCOV version 1.10