Exemple #1
0
    public IEndpointConventionBuilder AddEndpointBuilder(EndpointBuilder endpointBuilder)
    {
        var builder = new DefaultEndpointConventionBuilder(endpointBuilder);

        _endpointConventionBuilders.Add(builder);

        return(builder);
    }
    private TestEndpointConventionBuilder CreateBuilder()
    {
        var conventionBuilder = new DefaultEndpointConventionBuilder(new RouteEndpointBuilder(
                                                                         TestConstants.EmptyRequestDelegate,
                                                                         RoutePatternFactory.Parse("/test"),
                                                                         order: 0));

        return(new TestEndpointConventionBuilder(conventionBuilder));
    }
        private MvcEndpointDataSource CreateMvcEndpointDataSource(
            IActionDescriptorCollectionProvider actionDescriptorCollectionProvider = null,
            MvcEndpointInvokerFactory mvcEndpointInvokerFactory = null)
        {
            if (actionDescriptorCollectionProvider == null)
            {
                actionDescriptorCollectionProvider = new DefaultActionDescriptorCollectionProvider(
                    Array.Empty <IActionDescriptorProvider>(),
                    Array.Empty <IActionDescriptorChangeProvider>());
            }

            var services = new ServiceCollection();

            services.AddSingleton(actionDescriptorCollectionProvider);

            var routeOptionsSetup = new MvcCoreRouteOptionsSetup();

            services.Configure <RouteOptions>(routeOptionsSetup.Configure);
            services.AddRouting(options =>
            {
                options.ConstraintMap["upper-case"] = typeof(UpperCaseParameterTransform);
            });

            var serviceProvider = services.BuildServiceProvider();

            var dataSource = new MvcEndpointDataSource(
                actionDescriptorCollectionProvider,
                mvcEndpointInvokerFactory ?? new MvcEndpointInvokerFactory(new ActionInvokerFactory(Array.Empty <IActionInvokerProvider>())),
                serviceProvider.GetRequiredService <ParameterPolicyFactory>(),
                serviceProvider.GetRequiredService <RoutePatternTransformer>());

            var defaultEndpointConventionBuilder = new DefaultEndpointConventionBuilder();

            dataSource.AttributeRoutingConventionResolvers.Add((actionDescriptor) =>
            {
                return(defaultEndpointConventionBuilder);
            });

            return(dataSource);
        }
 public TestEndpointConventionBuilder(DefaultEndpointConventionBuilder endpointConventionBuilder)
 {
     _endpointConventionBuilder = endpointConventionBuilder;
 }