示例#1
0
        static HttpConfiguration NewConventionRouteConfiguration()
        {
            var configuration          = new HttpConfiguration();
            var controllerTypeResolver = new ControllerTypeCollection(
                typeof(ValuesController),
                typeof(Values2Controller),
                typeof(Values3Controller));

            configuration.Services.Replace(typeof(IHttpControllerTypeResolver), controllerTypeResolver);
            configuration.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = Optional });
            configuration.AddApiVersioning(
                options =>
            {
                options.Conventions.Controller <ValuesController>()
                .HasApiVersion(1, 0);
                options.Conventions.Controller <Values2Controller>()
                .HasApiVersion(2, 0)
                .HasDeprecatedApiVersion(3, 0, "beta")
                .HasApiVersion(3, 0)
                .Action(c => c.Post(default(ClassWithId))).MapToApiVersion(3, 0);
                options.Conventions.Controller <Values3Controller>()
                .HasApiVersion(4, 0)
                .AdvertisesApiVersion(5, 0);
            });

            return(configuration);
        }
示例#2
0
        public static HttpConfiguration NewOrdersConfiguration()
        {
            var configuration          = new HttpConfiguration();
            var controllerTypeResolver = new ControllerTypeCollection(
                typeof(Simulators.V1.OrdersController),
                typeof(Simulators.V2.OrdersController),
                typeof(Simulators.V3.OrdersController));

            configuration.Services.Replace(typeof(IHttpControllerTypeResolver), controllerTypeResolver);
            configuration.AddApiVersioning(
                options =>
            {
                options.Conventions.Controller <Simulators.V1.OrdersController>()
                .HasApiVersion(1, 0)
                .HasDeprecatedApiVersion(0, 9)
                .Action(c => c.Post(default(Order))).MapToApiVersion(1, 0);
                options.Conventions.Controller <Simulators.V2.OrdersController>()
                .HasApiVersion(2, 0);
                options.Conventions.Controller <Simulators.V3.OrdersController>()
                .HasApiVersion(3, 0)
                .AdvertisesApiVersion(4, 0);
            });
            var builder = new VersionedODataModelBuilder(configuration)
            {
                ModelConfigurations = { new OrderModelConfiguration() }
            };
            var models = builder.GetEdmModels();

            configuration.MapVersionedODataRoutes("odata", "api", models);

            return(configuration);
        }
示例#3
0
        static HttpConfiguration NewDirectRouteConfiguration()
        {
            var configuration          = new HttpConfiguration();
            var controllerTypeResolver = new ControllerTypeCollection(
                typeof(AttributeValues1Controller),
                typeof(AttributeValues2Controller),
                typeof(AttributeValues3Controller));

            configuration.Services.Replace(typeof(IHttpControllerTypeResolver), controllerTypeResolver);
            configuration.MapHttpAttributeRoutes();
            configuration.AddApiVersioning();

            return(configuration);
        }
示例#4
0
        public static HttpConfiguration NewOrdersConfiguration()
        {
            var configuration          = new HttpConfiguration();
            var controllerTypeResolver = new ControllerTypeCollection(
                typeof(Simulators.V1.OrdersController),
                typeof(Simulators.V2.OrdersController),
                typeof(Simulators.V3.OrdersController));

            configuration.Services.Replace(typeof(IHttpControllerTypeResolver), controllerTypeResolver);
            configuration.AddApiVersioning(
                options =>
            {
                options.Conventions.Controller <Simulators.V1.OrdersController>()
                .HasApiVersion(1, 0)
                .HasDeprecatedApiVersion(0, 9)
                .Action(c => c.Post(default)).MapToApiVersion(1, 0);
示例#5
0
        public static HttpConfiguration NewPeopleConfiguration()
        {
            var configuration          = new HttpConfiguration();
            var controllerTypeResolver = new ControllerTypeCollection(
                typeof(Simulators.V1.PeopleController),
                typeof(Simulators.V2.PeopleController),
                typeof(Simulators.V3.PeopleController));
            var builder = new VersionedODataModelBuilder(configuration)
            {
                ModelConfigurations = { new PersonModelConfiguration() }
            };
            var models = builder.GetEdmModels();

            configuration.Services.Replace(typeof(IHttpControllerTypeResolver), controllerTypeResolver);
            configuration.AddApiVersioning();
            configuration.MapVersionedODataRoutes("odata", "api/v{apiVersion}", models);

            return(configuration);
        }