public ODataActionSelector(IODataRoutingConvention convention,
     IActionDescriptorsCollectionProvider actionDescriptorsCollectionProvider,
     IActionSelectorDecisionTreeProvider decisionTreeProvider,
     IEnumerable<IActionConstraintProvider> actionConstraintProviders,
     ILoggerFactory loggerFactory)
 {
     _selector = new DefaultActionSelector(actionDescriptorsCollectionProvider, decisionTreeProvider, actionConstraintProviders, loggerFactory);
     _convention = convention;
 }
示例#2
0
 public ODataActionSelector(IODataRoutingConvention convention,
                            IActionDescriptorsCollectionProvider actionDescriptorsCollectionProvider,
                            IActionSelectorDecisionTreeProvider decisionTreeProvider,
                            IEnumerable <IActionConstraintProvider> actionConstraintProviders,
                            ILoggerFactory loggerFactory)
 {
     _selector   = new DefaultActionSelector(actionDescriptorsCollectionProvider, decisionTreeProvider, actionConstraintProviders, loggerFactory);
     _convention = convention;
 }
示例#3
0
        public void TestWebApi()
        {
            var pathHandler  = new DefaultODataPathHandler();
            var model        = new DataObjectEdmModel(new DataObjectEdmMetadata());
            var conventions  = new IODataRoutingConvention[0];
            var constraint   = new ODataPathRouteConstraint(pathHandler, model, "name", conventions);
            var route        = new ODataRoute("prefix", constraint);
            var assemblies   = new Assembly[0];
            var modelBuilder = new DefaultDataObjectEdmModelBuilder(assemblies);

            new PerRequestUpdateEdmModelHandler(new ManagementToken(route, model), modelBuilder);
        }
示例#4
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var handler     = new DefaultODataPathHandler(); // built-in
            var conventions = new IODataRoutingConvention[] {
                new DefaultMetadataRoutingConvention(Configuration["ExternalAPIAddress"]),
                new DefaultRoutingConvention() // custom
            };

            app.UseMvc(routeBuilder =>
            {
                routeBuilder.Select().Expand().Filter().OrderBy().MaxTop(100).Count().EnableContinueOnErrorHeader();
                routeBuilder.MapRoute("OpenApiDefinition", "openapi.json", new { controller = "OpenApi" });
                routeBuilder.MapODataServiceRoute("odata", null, GetEdmModel(), handler, conventions);
            });
        }
示例#5
0
 public ODataRoute(string routePrefix, IEdmModel model)
 {
     _routingConvention = new DefaultODataRoutingConvention();
     RoutePrefix        = routePrefix;
     _model             = model;
 }
 public ControllerAliasingODataRoutingConvention(IODataRoutingConvention delegateRoutingConvention, string controllerAlias, string targetControllerName)
 {
     this.delegateRoutingConvention = delegateRoutingConvention;
     this.controllerAlias = controllerAlias;
     this.targetControllerName = targetControllerName;
 }
示例#7
0
        /// <summary>
        /// Maps the specified versioned OData routes. When the <paramref name="newBatchHandler"/> is provided, it will create a '$batch' endpoint to handle the batch requests.
        /// </summary>
        /// <param name="builder">The extended <see cref="IRouteBuilder">route builder</see>.</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="models">The <see cref="IEnumerable{T}">sequence</see> of <see cref="IEdmModel">EDM models</see> to use for parsing OData paths.</param>
        /// <param name="pathHandler">The <see cref="IODataPathHandler">OData path handler</see> to use for parsing the OData path.</param>
        /// <param name="routingConventions">The <see cref="IEnumerable{T}">sequence</see> of <see cref="IODataRoutingConvention">OData routing conventions</see>
        /// to use for controller and action selection.</param>
        /// <param name="newBatchHandler">The <see cref="Func{TResult}">factory method</see> used to create new <see cref="ODataBatchHandler">OData batch handlers</see>.</param>
        /// <returns>The <see cref="IReadOnlyList{T}">read-only list</see> of added <see cref="ODataRoute">OData routes</see>.</returns>
        /// <remarks>The specified <paramref name="models"/> must contain the <see cref="ApiVersionAnnotation">API version annotation</see>.  This annotation is
        /// automatically applied when you use the <see cref="VersionedODataModelBuilder"/> and call <see cref="VersionedODataModelBuilder.GetEdmModels"/> to
        /// create the <paramref name="models"/>.</remarks>
        public static IReadOnlyList <ODataRoute> MapVersionedODataRoutes(
            this IRouteBuilder builder,
            string routeName,
            string routePrefix,
            IEnumerable <IEdmModel> models,
            IODataPathHandler pathHandler,
            IEnumerable <IODataRoutingConvention> routingConventions,
            Func <ODataBatchHandler> newBatchHandler)
        {
            Arg.NotNull(builder, nameof(builder));
            Arg.NotNullOrEmpty(routeName, nameof(routeName));
            Arg.NotNull(models, nameof(models));
            Contract.Ensures(Contract.Result <IReadOnlyList <ODataRoute> >() != null);

            var serviceProvider          = builder.ServiceProvider;
            var options                  = serviceProvider.GetRequiredService <ODataOptions>();
            var routeCollection          = serviceProvider.GetRequiredService <IODataRouteCollectionProvider>();
            var inlineConstraintResolver = serviceProvider.GetRequiredService <IInlineConstraintResolver>();
            var routeConventions         = VersionedODataRoutingConventions.AddOrUpdate(routingConventions.ToList());
            var routes                 = builder.Routes;
            var perRouteContainer      = serviceProvider.GetRequiredService <IPerRouteContainer>();
            var odataRoutes            = new List <ODataRoute>();
            var unversionedConstraints = new List <IRouteConstraint>();

            if (pathHandler != null && pathHandler.UrlKeyDelimiter == null)
            {
                pathHandler.UrlKeyDelimiter = options.UrlKeyDelimiter;
            }

            foreach (var model in models)
            {
                var versionedRouteName = routeName;
                var apiVersion         = model.GetAnnotationValue <ApiVersionAnnotation>(model)?.ApiVersion;
                var routeConstraint    = MakeVersionedODataRouteConstraint(apiVersion, ref versionedRouteName);

                IEnumerable <IODataRoutingConvention> NewRouteConventions(IServiceProvider services)
                {
                    var conventions = new IODataRoutingConvention[routeConventions.Count + 1];

                    conventions[0] = new VersionedAttributeRoutingConvention(versionedRouteName, serviceProvider, apiVersion);
                    routeConventions.CopyTo(conventions, 1);
                    return(conventions);
                }

                var edm             = model;
                var batchHandler    = newBatchHandler?.Invoke();
                var configureAction = builder.ConfigureDefaultServices(container =>
                                                                       container.AddService(Singleton, typeof(IEdmModel), sp => edm)
                                                                       .AddService(Singleton, typeof(IODataPathHandler), sp => pathHandler)
                                                                       .AddService(Singleton, typeof(IEnumerable <IODataRoutingConvention>), NewRouteConventions)
                                                                       .AddService(Singleton, typeof(ODataBatchHandler), sp => batchHandler));
                var rootContainer = perRouteContainer.CreateODataRootContainer(versionedRouteName, configureAction);
                var router        = rootContainer.GetService <IRouter>() ?? builder.DefaultHandler;
                var route         = new ODataRoute(router, versionedRouteName, routePrefix.RemoveTrailingSlash(), routeConstraint, inlineConstraintResolver);

                unversionedConstraints.Add(new ODataPathRouteConstraint(versionedRouteName));
                builder.ConfigureBatchHandler(batchHandler, route);
                routes.Add(route);
                odataRoutes.Add(route);
                routeCollection.Add(new ODataRouteMapping(route, apiVersion, rootContainer));
            }

            builder.AddRouteToRespondWithBadRequestWhenAtLeastOneRouteCouldMatch(routeName, routePrefix, unversionedConstraints, inlineConstraintResolver);
            NotifyRoutesMapped();

            return(odataRoutes);
        }
示例#8
0
		public ODataRoute(string routePrefix, IEdmModel model)
        {
            _routingConvention = new DefaultODataRoutingConvention();
            RoutePrefix = routePrefix;
            _model = model;
        }
 public ControllerAliasingODataRoutingConvention(IODataRoutingConvention delegateRoutingConvention, string controllerAlias, string targetControllerName)
 {
     _delegateRoutingConvention = delegateRoutingConvention;
     _controllerAlias           = controllerAlias;
     _targetControllerName      = targetControllerName;
 }
示例#10
0
 public VersionedRoutingConvention(IODataRoutingConvention innerRoutingConvention, string versionSuffix)
 {
     _innerRoutingConvention = innerRoutingConvention;
     _versionSuffix          = versionSuffix;
 }
 public VersionedRoutingConvention(IODataRoutingConvention innerRoutingConvention, string versionSuffix)
 {
     _innerRoutingConvention = innerRoutingConvention;
     _versionSuffix = versionSuffix;
 }