Example #1
0
 /// <summary>
 /// Maps the specified OData route and the OData route attributes. When the <paramref name="batchHandler"/> is
 /// non-<c>null</c>, it will create a '$batch' endpoint to handle the batch requests.
 /// </summary>
 /// <param name="builder">The <see cref="IRouteBuilder"/> to add the route to.</param>
 /// <param name="routeName">The name of the route to map.</param>
 /// <param name="routePrefix">The prefix to add to the OData route's path template.</param>
 /// <param name="model">The EDM model to use for parsing OData paths.</param>
 /// <param name="batchHandler">The <see cref="ODataBatchHandler"/>.</param>
 /// <returns>The added <see cref="ODataRoute"/>.</returns>
 public static ODataRoute MapODataServiceRoute(this IRouteBuilder builder, string routeName,
                                               string routePrefix, IEdmModel model, ODataBatchHandler batchHandler)
 {
     return(builder.MapODataServiceRoute(routeName, routePrefix, containerBuilder =>
                                         containerBuilder.AddService(ServiceLifetime.Singleton, sp => model)
                                         .AddService(ServiceLifetime.Singleton, sp => batchHandler)
                                         .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                              ODataRoutingConventions.CreateDefaultWithAttributeRouting(routeName, builder))));
 }
Example #2
0
 protected override void UpdateConfiguration(WebRouteConfiguration configuration)
 {
     configuration.AddControllers(typeof(CustomersController), typeof(OrdersController));
     configuration.JsonReferenceLoopHandling =
         Newtonsoft.Json.ReferenceLoopHandling.Ignore;
     configuration.MapODataServiceRoute("customserializer", "customserializer", builder =>
                                        builder.AddService(ServiceLifetime.Singleton, sp => EdmModel.GetEdmModel(configuration))
                                        .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                             ODataRoutingConventions.CreateDefaultWithAttributeRouting("customserializer", configuration))
                                        .AddService <ODataSerializerProvider, MyODataSerializerProvider>(ServiceLifetime.Singleton)
                                        .AddService <ODataResourceSerializer, AnnotatingEntitySerializer>(ServiceLifetime.Singleton));
 }
        protected override void UpdateConfiguration(WebRouteConfiguration configuration)
        {
            var controllers = new[] { typeof(CustomersController), typeof(OrdersController), typeof(MetadataController) };

            configuration.AddControllers(controllers);

            configuration.Routes.Clear();

            configuration.MapODataServiceRoute("odata", "odata",
                                               builder =>
                                               builder.AddService(ServiceLifetime.Singleton, sp => UriParserExtenstionEdmModel.GetEdmModel(configuration))
                                               .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                                    ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", configuration))
                                               .AddService <ODataUriResolver>(ServiceLifetime.Singleton, sp =>
                                                                              new StringAsEnumResolver()
            {
                EnableCaseInsensitive = true
            }));

            configuration.EnsureInitialized();
        }
Example #4
0
        public static void Register(HttpConfiguration config)
        {
            var model = GetEdmModel();

            config.MapODataServiceRoute("OData", "OData", b => b
                                        .AddService <IEdmModel>(ServiceLifetime.Singleton, s => model)
                                        .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, s => ODataRoutingConventions.CreateDefaultWithAttributeRouting("OData", config))
                                        .AddService <ODataUriResolver>(ServiceLifetime.Singleton, s => new AlternateKeysODataUriResolver(model))
                                        );
        }
Example #5
0
        public void Configure(IApplicationBuilder app)
        {
            if (_environment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseCors(builder => builder
                            .AllowAnyOrigin()
                            .AllowAnyMethod()
                            .AllowAnyHeader()
                            .AllowCredentials());
            }
            else
            {
                app.UseHsts();
                app.UseHttpsRedirection();
            }

            app.UseSerilogRequestLogging();

            app.UseAuthentication();

            app.UseMvc(builder =>
            {
                builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();

                const string routeName = "odata";
                builder.MapODataServiceRoute(routeName, routeName, routeBuilder => routeBuilder
                                             .AddService(ServiceLifetime.Singleton, sp => GetEdmModel())
                                             .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton,
                                                                                                  sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting(routeName, builder))
                                             );
            });
        }
 /// <summary>
 /// Maps the specified OData route and the OData route attributes. When the <paramref name="defaultHandler"/>
 /// is non-<c>null</c>, it will map it as the default handler for the route.
 /// </summary>
 /// <param name="configuration">The server configuration.</param>
 /// <param name="routeName">The name of the route to map.</param>
 /// <param name="routePrefix">The prefix to add to the OData route's path template.</param>
 /// <param name="model">The EDM model to use for parsing OData paths.</param>
 /// <param name="defaultHandler">The default <see cref="HttpMessageHandler"/> for this route.</param>
 /// <returns>The added <see cref="ODataRoute"/>.</returns>
 public static ODataRoute MapODataServiceRoute(this HttpConfiguration configuration, string routeName,
                                               string routePrefix, IEdmModel model, HttpMessageHandler defaultHandler)
 {
     return(MapODataServiceRoute(configuration, routeName, routePrefix, model, new DefaultODataPathHandler(),
                                 ODataRoutingConventions.CreateDefaultWithAttributeRouting(configuration, model), defaultHandler));
 }
Example #7
0
 public static void UpdateConfiguration(HttpConfiguration configuration)
 {
     configuration.Services.Replace(
         typeof(IAssembliesResolver),
         new TestAssemblyResolver(typeof(CustomersController), typeof(OrdersController)));
     configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
     configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling =
         Newtonsoft.Json.ReferenceLoopHandling.Ignore;
     configuration.MapODataServiceRoute("dependencyinjection", "dependencyinjection", builder =>
                                        builder.AddService(ServiceLifetime.Singleton, sp => EdmModel.GetEdmModel())
                                        .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                             ODataRoutingConventions.CreateDefaultWithAttributeRouting("dependencyinjection", configuration))
                                        .AddService <CountQueryValidator, MyCountQueryValidator>(ServiceLifetime.Singleton));
 }
Example #8
0
        private static HttpConfiguration GetQueryOptionConfiguration(bool caseInsensitive)
        {
            var config = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(ParserExtenstionCustomersController) });
            ODataUriResolver resolver = new ODataUriResolver
            {
                EnableCaseInsensitive = caseInsensitive,
            };

            config.Count().OrderBy().Filter().Expand().MaxTop(null).Select();
            config.MapODataServiceRoute("query", "query",
                                        builder =>
                                        builder.AddService(ServiceLifetime.Singleton, sp => GetEdmModel())
                                        .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                             ODataRoutingConventions.CreateDefaultWithAttributeRouting("query", config))
                                        .AddService(ServiceLifetime.Singleton, sp => resolver));
            return(config);
        }
Example #9
0
        public async Task ExtensionResolver_Works_EnumPrefixFree(string parameter, bool enableEnumPrefix, HttpStatusCode statusCode)
        {
            // Arrange
            IEdmModel        model    = GetEdmModel();
            var              config   = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(ParserExtenstionCustomersController) });
            ODataUriResolver resolver = new ODataUriResolver();

            if (enableEnumPrefix)
            {
                resolver = new StringAsEnumResolver();
            }

            config.MapODataServiceRoute("odata", "odata",
                                        builder =>
                                        builder.AddService(ServiceLifetime.Singleton, sp => model)
                                        .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                             ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", config))
                                        .AddService(ServiceLifetime.Singleton, sp => resolver));
            HttpClient client = new HttpClient(new HttpServer(config));

            // Act
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,
                                                                String.Format("http://localhost/odata/ParserExtenstionCustomers/Default.GetCustomerByGender({0})", parameter));
            HttpResponseMessage response = await client.SendAsync(request);

            // Assert
            Assert.Equal(statusCode, response.StatusCode);

            if (statusCode == HttpStatusCode.OK)
            {
                Assert.Equal("GetCustomerByGender/Male", (response.Content as ObjectContent <string>).Value);
            }
        }
Example #10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseStaticFiles();
            app.UseSpaStaticFiles();
            app.UseCors(builder => builder.AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin());

            app.UseSignalR(routes =>
            {
                routes.MapHub <TaskHub>("/taskHub");
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");

                routes.SetTimeZoneInfo(TimeZoneInfo.Utc);
                routes.MapODataServiceRoute("ODataRoute", "api", builder => builder
                                            .AddService(Microsoft.OData.ServiceLifetime.Singleton, sp => ODataConfig.BuildEdmModel(app.ApplicationServices))
                                            .AddService <IEnumerable <IODataRoutingConvention> >(Microsoft.OData.ServiceLifetime.Singleton, sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting("ODataRoute", routes))
                                            .AddService <ODataUriResolver>(Microsoft.OData.ServiceLifetime.Singleton, sp => new StringAsEnumResolver {
                    EnableCaseInsensitive = true
                }));
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });


            AutoMapperConfig.RegisterMappings();
            EnsureDbCreated(app);
        }
Example #11
0
        private static HttpConfiguration GetConfiguration(bool caseInsensitive, bool unqualifiedNameCall)
        {
            IEdmModel         model  = ODataRoutingModel.GetModel();
            HttpConfiguration config = RoutingConfigurationFactory.CreateWithTypes(new[]
            {
                typeof(MetadataController),
                typeof(ProductsController),
                typeof(RoutingCustomersController),
            });

            ODataUriResolver resolver = new ODataUriResolver();

            if (unqualifiedNameCall)
            {
                resolver = new UnqualifiedODataUriResolver();
            }
            resolver.EnableCaseInsensitive = caseInsensitive;

            config.Count().Filter().OrderBy().Expand().MaxTop(null).Select();
            config.MapODataServiceRoute("odata", "odata",
                                        builder =>
                                        builder.AddService(ServiceLifetime.Singleton, sp => model)
                                        .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                             ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", config))
                                        .AddService(ServiceLifetime.Singleton, sp => resolver));
            return(config);
        }
        public static void Register(HttpConfiguration config)
        {
            // TODO: ?? do we need eliminating necessity using full-qualified names ??:
            // http://odata.github.io/WebApi/#06-01-custom-url-parsing
//            config.EnableCaseInsensitive(caseInsensitive: true);
//            config.EnableUnqualifiedNameCall(unqualifiedNameCall: true);

            config.Count().Filter().OrderBy().Expand().Select().MaxTop(null); //new line

            _routeName = "DefaultODataRoute";
            config.MapODataServiceRoute(_routeName, RoutePrefix,
                                        // edmModel
                                        builder => ContainerBuilderExtensions.AddService(builder, ServiceLifetime.Singleton, sp => EdmModel)
                                        .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton,
                                                                                             sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting(_routeName, config))
                                        .AddService <ODataUriResolver>(ServiceLifetime.Singleton, sp => new StringAsEnumResolver {
                EnableCaseInsensitive = true
            })
                                        );
            config.EnsureInitialized();
        }
Example #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            var path = PlatformServices.Default.Application.ApplicationBasePath;

            if (!path.Contains("OData.Tests"))
            {
                //configure NLog
                loggerFactory.AddNLog(new NLogProviderOptions {
                    CaptureMessageTemplates = true, CaptureMessageProperties = true
                });
                loggerFactory.ConfigureNLog("nlog.config");
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            IEdmModel model = GetEdmModel(app.ApplicationServices);

            ODataSimplifiedOptions odata_options = new ODataSimplifiedOptions()
            {
                EnableWritingODataAnnotationWithoutPrefix = false
            };

            app.UseCors(x => x.AllowAnyHeader().AllowAnyMethod().AllowCredentials().WithOrigins("*"));

            app.Map("/odata/api",
                    api =>
            {
                api.UseMvc(routeBuilder =>
                {
                    routeBuilder.Select().Expand().Filter().OrderBy().MaxTop(null).Count();

                    string odata_route_name = "ODataRoute";
                    routeBuilder.MapODataServiceRoute(odata_route_name, "data", a =>
                    {
                        a.AddService(Microsoft.OData.ServiceLifetime.Singleton, sp => model);
                        a.AddService <IODataPathHandler>(Microsoft.OData.ServiceLifetime.Singleton,
                                                         sp => new DefaultODataPathHandler());
                        a.AddService <IEnumerable <IODataRoutingConvention> >(
                            Microsoft.OData.ServiceLifetime.Singleton,
                            sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting(odata_route_name,
                                                                                            routeBuilder));
                        a.AddService <ODataSerializerProvider>(Microsoft.OData.ServiceLifetime.Singleton,
                                                               sp => new SampleODataSerializerProvider(sp, loggerFactory));
                        a.AddService <ODataDeserializerProvider>(Microsoft.OData.ServiceLifetime.Singleton,
                                                                 sp => new DefaultODataDeserializerProvider(sp));
                        a.AddService <ILoggerFactory>(Microsoft.OData.ServiceLifetime.Singleton,
                                                      sp => loggerFactory);
                        a.AddService <ODataSimplifiedOptions>(Microsoft.OData.ServiceLifetime.Singleton,
                                                              sp => odata_options);
                        a.AddService <ODataPayloadValueConverter, SampleODataPayloadValueConverter>(Microsoft.OData
                                                                                                    .ServiceLifetime.Singleton);
                    });
                    routeBuilder.EnableDependencyInjection();
                });
            });

            var webSocketOptions = new Microsoft.AspNetCore.Builder.WebSocketOptions()
            {
                KeepAliveInterval = TimeSpan.FromSeconds(5),
                ReceiveBufferSize = 999999
            };
        }
Example #14
0
        protected override void UpdateConfiguration(WebRouteConfiguration config)
        {
            var controllers = new[] { typeof(UnqualifiedCarsController) };

            config.AddControllers(controllers);

            config.Routes.Clear();
            config.MapODataServiceRoute("odata", "odata", builder =>
                                        builder.AddService(ServiceLifetime.Singleton, sp => GetModel(config))
                                        .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                             ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", config))
                                        .AddService <ODataUriResolver>(ServiceLifetime.Singleton, sp => new UnqualifiedODataUriResolver()));
        }
 /// <summary>
 /// Maps the specified OData route and the OData route attributes. When the <paramref name="defaultHandler"/>
 /// is non-<c>null</c>, it will map it as the default handler for the route.
 /// </summary>
 /// <param name="configuration">The server configuration.</param>
 /// <param name="routeName">The name of the route to map.</param>
 /// <param name="routePrefix">The prefix to add to the OData route's path template.</param>
 /// <param name="model">The EDM model to use for parsing OData paths.</param>
 /// <param name="defaultHandler">The default <see cref="HttpMessageHandler"/> for this route.</param>
 /// <returns>The added <see cref="ODataRoute"/>.</returns>
 public static ODataRoute MapODataServiceRoute(this HttpConfiguration configuration, string routeName,
                                               string routePrefix, IEdmModel model, HttpMessageHandler defaultHandler)
 {
     return(configuration.MapODataServiceRoute(routeName, routePrefix, builder =>
                                               builder.AddService(ServiceLifetime.Singleton, sp => model)
                                               .AddService(ServiceLifetime.Singleton, sp => defaultHandler)
                                               .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                                    ODataRoutingConventions.CreateDefaultWithAttributeRouting(routeName, configuration))));
 }
Example #16
0
        public async Task ExtensionResolver_Works_EnumPrefixFree_QueryOption(string query, bool enableEnumPrefix, HttpStatusCode statusCode, string output)
        {
            // Arrange
            IEdmModel        model    = GetEdmModel();
            var              config   = RoutingConfigurationFactory.CreateWithTypes(new[] { typeof(ParserExtenstionCustomersController) });
            ODataUriResolver resolver = new ODataUriResolver();

            if (enableEnumPrefix)
            {
                resolver = new StringAsEnumResolver();
            }

            config.MapODataServiceRoute("odata", "odata",
                                        builder =>
                                        builder.AddService(ServiceLifetime.Singleton, sp => model)
                                        .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                             ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", config))
                                        .AddService(ServiceLifetime.Singleton, sp => resolver));
            HttpClient client = new HttpClient(new HttpServer(config));

            // Act
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,
                                                                String.Format("http://localhost/odata/ParserExtenstionCustomers?{0}", query));
            HttpResponseMessage response = await client.SendAsync(request);

            // Assert
            Assert.Equal(statusCode, response.StatusCode);

            if (statusCode == HttpStatusCode.OK)
            {
                JObject content = await response.Content.ReadAsAsync <JObject>();

                Assert.Equal(output, String.Join(",", content["value"].Select(e => e["Id"])));
            }
        }
        /// <summary>
        /// Configures the application using the provided builder, hosting environment, and logging factory.
        /// </summary>
        /// <param name="app">The current application builder.</param>
        /// <param name="env">The current hosting environment.</param>
        /// <param name="httpContextAccessor">Allows access to the HTTP context including request/response</param>
        /// <param name="modelBuilder">The <see cref="VersionedODataModelBuilder">model builder</see> used to create OData entity data models (EDMs).</param>
        /// <param name="provider">The API version descriptor provider used to enumerate defined API versions.</param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IHttpContextAccessor httpContextAccessor, VersionedODataModelBuilder modelBuilder, IApiVersionDescriptionProvider provider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            var httpRequestLoggingLevel = Configuration.GetValue <string>("ApplicationInsights:HttpRequestLoggingLevel");

            app.UseCors("AllOrigins");
            app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseClientRateLimiting();
            // Add mock data to the database if it is empty (demo uses in memory database only, so always starts empty)
            var context = app.ApplicationServices.GetService <ApiDbContext>();

            MockData.AddMockData(context);
            // Add custom telemetry initializer to add user name from the HTTP context
            app.UseMiddleware <CaptureRequestMiddleware>(httpRequestLoggingLevel);
            var configuration = app.ApplicationServices.GetService <TelemetryConfiguration>();

            configuration.TelemetryInitializers.Add(new TelemetryInitializer(httpContextAccessor));
            app.UseODataBatching();
            app.UseApiVersioning(); // added to fix issue outlined in https://github.com/OData/WebApi/issues/1754
            app.UseMvc(routes => {
                routes.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
                routes.MapVersionedODataRoutes("ODataRoute", "odata", modelBuilder.GetEdmModels());
                routes.MapODataServiceRoute("ODataBatch", null,
                                            configureAction: containerBuilder => containerBuilder
                                            .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(IEdmModel),
                                                        sp => modelBuilder.GetEdmModels().First())
                                            .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(IEnumerable <IODataRoutingConvention>),
                                                        sp => ODataRoutingConventions.CreateDefaultWithAttributeRouting("ODataBatch", routes))
                                            .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(ODataBatchHandler),
                                                        sp => {
                    var oDataBatchHandler = new TransactionalODataBatchHandler();
                    oDataBatchHandler.MessageQuotas.MaxOperationsPerChangeset = 5000;
                    return(oDataBatchHandler);
                })
                                            .AddService(Microsoft.OData.ServiceLifetime.Singleton, typeof(ODataMessageReaderSettings),
                                                        sp => {
                    ODataMessageReaderSettings odataMessageReaderSettings = new ODataMessageReaderSettings();
                    odataMessageReaderSettings.MessageQuotas.MaxOperationsPerChangeset = 5000;
                    return(odataMessageReaderSettings);
                })
                                            );
                routes.EnableDependencyInjection();
            });
            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();
            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(options => {
                foreach (var description in provider.ApiVersionDescriptions)
                {
                    options.SwaggerEndpoint(
                        $"/swagger/{description.GroupName}/swagger.json",
                        description.GroupName.ToUpperInvariant());
                }
                options.DefaultModelExpandDepth(2);
                options.DefaultModelsExpandDepth(-1);
                options.DefaultModelRendering(ModelRendering.Model);
                options.DisplayRequestDuration();
                options.DocExpansion(DocExpansion.None);
            });
        }
Example #18
0
        public static void UpdateConfiguration(HttpConfiguration configuration)
        {
            var controllers = new[] { typeof(CustomersController), typeof(OrdersController), typeof(MetadataController) };
            TestAssemblyResolver resolver = new TestAssemblyResolver(new TypesInjectionAssembly(controllers));

            configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
            configuration.Services.Replace(typeof(IAssembliesResolver), resolver);

            configuration.Routes.Clear();

            configuration.Count().Filter().OrderBy().Expand().MaxTop(null);

            configuration.MapODataServiceRoute("odata", "odata",
                                               builder =>
                                               builder.AddService(ServiceLifetime.Singleton, sp => UriParserExtenstionEdmModel.GetEdmModel())
                                               .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                                    ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", configuration))
                                               .AddService <ODataUriResolver>(ServiceLifetime.Singleton, sp => new CaseInsensitiveResolver()));

            configuration.EnsureInitialized();
        }
Example #19
0
        protected override void UpdateConfiguration(WebRouteConfiguration configuration)
        {
            var controllers = new[]
            {
                typeof(CustomersController), typeof(OrdersController), typeof(PeopleController),
                typeof(CompaniesController), typeof(MetadataController)
            };

            configuration.AddControllers(controllers);

            IEdmModel model = AlternateKeysEdmModel.GetEdmModel();

            configuration.Routes.Clear();

            configuration.Count().Filter().OrderBy().Expand().MaxTop(null);

            configuration.MapODataServiceRoute("odata", "odata",
                                               builder =>
                                               builder.AddService(ServiceLifetime.Singleton, sp => model)
                                               .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                                    ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", configuration))
                                               .AddService <ODataUriResolver>(ServiceLifetime.Singleton, sp => new AlternateKeysODataUriResolver(model)));

            configuration.EnsureInitialized();
        }
Example #20
0
        protected override void UpdateConfiguration(WebRouteConfiguration config)
        {
            var controllers = new[] { typeof(CustomersController), typeof(OrdersController), typeof(AddressesController) };

            config.AddControllers(controllers);

            config.Routes.Clear();

            config.MapODataServiceRoute("odata", "",
                                        builder =>
                                        builder.AddService(ServiceLifetime.Singleton, sp => GetModel(config))
                                        .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp =>
                                                                                             ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", config))
                                        .AddService(ServiceLifetime.Singleton, sp => new CaseInsensitiveResolver()));
        }