#pragma warning restore CA1823 // Do not declare static members on generic types /// TODO GitHubIssue#51 : Support model lazy loading /// <summary> /// Maps the API routes to the RestierController. /// </summary> /// <typeparam name="TApi">The user API.</typeparam> /// <param name="config">The <see cref="HttpConfiguration"/> instance.</param> /// <param name="routeName">The name of the route.</param> /// <param name="routePrefix">The prefix of the route.</param> /// <param name="batchHandler">The handler for batch requests.</param> /// <returns>The task object containing the resulted <see cref="ODataRoute"/> instance.</returns> public static Task <ODataRoute> MapRestierRoute <TApi>( this HttpConfiguration config, string routeName, string routePrefix, RestierBatchHandler batchHandler = null) where TApi : ApiBase { // This will be added a service to callback stored in ApiConfiguration // Callback is called by ApiBase.AddApiServices method to add real services. ApiBase.AddPublisherServices(typeof(TApi), services => { services.AddODataServices <TApi>(); }); IContainerBuilder func() => new RestierContainerBuilder(typeof(TApi)); config.UseCustomContainerBuilder(func); var conventions = CreateRestierRoutingConventions(config, routeName); if (batchHandler != null) { batchHandler.ODataRouteName = routeName; } void configureAction(IContainerBuilder builder) => builder .AddService <IEnumerable <IODataRoutingConvention> >(ServiceLifetime.Singleton, sp => conventions) .AddService <ODataBatchHandler>(ServiceLifetime.Singleton, sp => batchHandler); var route = config.MapODataServiceRoute(routeName, routePrefix, configureAction); return(Task.FromResult(route)); }
public async Task VerifyMetadataPropertyType() { ApiBase.AddPublisherServices(typeof(PrimitivesApi), services => { services.AddODataServices <PrimitivesApi>(); }); var container = new RestierContainerBuilder(typeof(PrimitivesApi)); var provider = container.BuildContainer(); var api = provider.GetService <ApiBase>(); var edmModel = await api.GetModelAsync(); var entityType = (IEdmEntityType) edmModel.FindDeclaredType(@"Microsoft.Restier.Providers.EntityFramework7.Tests.Models.Primitives.DateItem"); Assert.NotNull(entityType); Assert.True(entityType.FindProperty("DTProperty").Type.IsDateTimeOffset()); Assert.True(entityType.FindProperty("DateProperty").Type.IsDate()); Assert.True(entityType.FindProperty("TODProperty").Type.IsTimeOfDay()); Assert.True(entityType.FindProperty("TSProperty").Type.IsDuration()); }