Esempio n. 1
0
        /// <summary>
        /// Gets the current API logger.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">The IPGPLogger is not registered in the Api Services.</exception>
        public static IPGPLogger GetCurrentApiLogger(this ServicesContainer service)
        {
            var logger = ApiServicesHelper.GetRegisteredService <IPGPLogger>();

            if (logger == null)
            {
                throw new InvalidOperationException("The IPGPLogger is not registered in the ApiServiceHelper.");
            }

            return(logger);
        }
Esempio n. 2
0
        /// <summary>
        /// Registers the specified configuration.
        /// </summary>
        /// <param name="config">The configuration.</param>
        public static void Register(HttpConfiguration config)
        {
            var apiMessageHandler = new MessageHandler();

            DomainMessageHelper.MessageHandler = apiMessageHandler;
            ApiServicesHelper.RegisterService <IPGPLogger>(new PGPApiLogger());

            // Web API configuration and services
            ErrorHandlersConfig.SetupExceptionHandlers(config, apiMessageHandler,
                                                       config.Services.GetCurrentApiLogger());
            FormattersConfig.SetupApiFormatters(config);

            // AutoMapper
            AutoMapperConfig.RegisterMapping();

            // Web API routes
            config.MapHttpAttributeRoutes();

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