Пример #1
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            config.Services.Replace(typeof(IExceptionLogger), new UnhandledExceptionLogger());
            config.Services.Replace(typeof(IExceptionHandler), new GlobalExceptionHandler());

            // Web API configuration and services
            var serializer = config.Formatters.JsonFormatter.CreateJsonSerializer();

            serializer.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());

            config.Formatters.JsonFormatter.SerializerSettings =
                new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                NullValueHandling     = NullValueHandling.Ignore,
                ContractResolver      = new CamelCasePropertyNamesContractResolver()
            };
            config.Formatters.Clear();
            config.Formatters.Insert(0, new JsonMediaTypeFormatter());

            //EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*");
            //config.EnableCors(cors);

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "WebApi/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            ODataConfig.Register(config);
        }
Пример #2
0
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            var container = UnityRegisterType.RegisterType();

            config.DependencyResolver = new UnityResolver(container);

            //bacfground FluentScheduler
            JobManager.UseUtcTime();
            JobManager.JobFactory = new JobFactory(container);
            JobManager.Initialize(new FluentSchedulerRegistry());

            //OData
            ODataConfig.ODataRegister(config);
        }