public static void Setup(TestContext ctx)
 {
     IntegrationTestManager.Startup(c => {
         ApiVersioning.Configure(c)
         .ConfigureRequestVersionDetector <DefaultRouteKeyVersionDetector>();
     });
 }
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            config.SetDocumentationProvider(
                new XmlDocumentationProvider(
                    HostingEnvironment.MapPath("~/bin/" + typeof(WebApiConfig).Assembly.GetName().Name + ".xml")));

            var dependencyContainer = new TinyIoCContainer();

            // API versioning
            config.Services.Replace(typeof(IHttpControllerSelector), new VersionedApiControllerSelector(config));
            config.Services.Replace(typeof(IApiExplorer), new VersionedApiExplorer(config));
            config.DependencyResolver = new DependencyResolver(dependencyContainer);

            dependencyContainer.Register((c, np) => new DefaultControllerIdentificationDetector(config));
            dependencyContainer.Register((c, np) => new DefaultRequestControllerIdentificationDetector(config));

            ApiVersioning.Configure(config)
            .ConfigureRequestVersionDetector <DefaultRouteKeyVersionDetector>();

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute("DefaultApi", "api/v{version}/{controller}/{id}", new { id = RouteParameter.Optional });
        }
Exemple #3
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            config.EnableCors(new EnableCorsAttribute(ConfigurationManager.AppSettings["webapp"], "*", "PUT, HEAD, OPTIONS, GET, POST, DELETE"));

            var dependencyContainer = new TinyIoCContainer();

            // API VERSIONING
            // [email protected]:Sebazzz/SDammann.WebApi.Versioning.git Commit: 08ec8ed339b564996743ad0fff13953fe1e95b33
            config.Services.Replace(typeof(IHttpControllerSelector), new MyVersionedApiControllerSelector(config));
            config.Services.Replace(typeof(IApiExplorer), new VersionedApiExplorer(config));
            config.DependencyResolver = new DependencyResolver(dependencyContainer);

            dependencyContainer.Register((c, np) => new DefaultControllerIdentificationDetector(config));
            dependencyContainer.Register((c, np) => new DefaultRequestControllerIdentificationDetector(config));

            RegisterServices(dependencyContainer);
            RegisterControllers(dependencyContainer);

            ApiVersioning.Configure()
            .ConfigureRequestVersionDetector <DefaultRouteKeyVersionDetector>();

            // Web API routes
            config.MapHttpAttributeRoutes();
            ConfigParameterBindings(config);
            ConfigApiRoutes(config);
            ConfigFilters(config);
        }
        public static void Register(HttpConfiguration config)
        {
            //Cors
            config.EnableCors();

            //Formaters
            config.Formatters.Add(new CsvFormatter(new QueryStringMapping("format", "csv", "text/csv")));
            //config.Formatters.Add(new XmlFormatter(new QueryStringMapping("format", "xml", "application/xml")));

            var dependencyContainer = new TinyIoCContainer();

            //// API versioning
            config.Services.Replace(typeof(IHttpControllerSelector), new VersionedApiControllerSelector(config));
            config.Services.Replace(typeof(IApiExplorer), new VersionedApiExplorer(config));
            config.DependencyResolver = new DependencyResolver(dependencyContainer);

            dependencyContainer.Register((c, np) => new DefaultControllerIdentificationDetector(config));
            dependencyContainer.Register((c, np) => new DefaultRequestControllerIdentificationDetector(config));

            ApiVersioning.Configure(config).ConfigureRequestVersionDetector <DefaultRouteKeyVersionDetector>();

            //// Web API routes
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute("DefaultApi", "v{version}/{controller}/{id}",
                                       new { id = RouteParameter.Optional });
            config.Routes.MapHttpRoute("Error404", "{*url}", new { controller = "Error", action = "Handle404" });
            config.Routes.MapHttpRoute("Error405", "{*url}", new { controller = "Error", action = "Handle405" });

            //Services
            config.Services.Replace(typeof(IExceptionHandler), new GlobalExceptionHandler());
            //config.Services.Replace(typeof(IHttpControllerSelector), new HttpNotFoundAwareDefaultHttpControllerSelector(config));
            //config.Services.Replace(typeof(IHttpActionSelector), new HttpNotFoundAwareControllerActionSelector());

            //Handlers
            config.MessageHandlers.Add(new LanguageNegotiationHandler());
            config.MessageHandlers.Add(new UniqueRequestIdentifierHandler());
            config.MessageHandlers.Add(new ResourceOptionsHandler());
            config.MessageHandlers.Add(new CompressionNegotiationHandler());

            FilterConfig.RegisterHttpFilters(config.Filters);
        }