Beispiel #1
0
 public RouteProvider(NtradaOptions options, IRequestHandlerManager requestHandlerManager,
                      IRouteConfigurator routeConfigurator, IRequestExecutionValidator requestExecutionValidator,
                      IUpstreamBuilder upstreamBuilder, ILogger <RouteProvider> logger)
 {
     _routeConfigurator         = routeConfigurator;
     _requestExecutionValidator = requestExecutionValidator;
     _upstreamBuilder           = upstreamBuilder;
     _options = options;
     _requestHandlerManager = requestHandlerManager;
     _logger  = logger;
     _methods = new Dictionary <string, Action <IRouteBuilder, string, RouteConfig> >
     {
         ["get"] = (builder, path, routeConfig) =>
                   builder.MapGet(path,
                                  (request, response, routeData) => Handle(request, response, routeData, routeConfig)),
         ["post"] = (builder, path, routeConfig) =>
                    builder.MapPost(path,
                                    (request, response, routeData) => Handle(request, response, routeData, routeConfig)),
         ["put"] = (builder, path, routeConfig) =>
                   builder.MapPut(path,
                                  (request, response, routeData) => Handle(request, response, routeData, routeConfig)),
         ["delete"] = (builder, path, routeConfig) =>
                      builder.MapDelete(path,
                                        (request, response, routeData) => Handle(request, response, routeData, routeConfig)),
         ["patch"] = (builder, path, routeConfig) =>
                     builder.MapVerb("patch", path,
                                     (request, response, routeData) => Handle(request, response, routeData, routeConfig)),
     };
 }
Beispiel #2
0
        public RouteProvider(IServiceProvider serviceProvider, IRequestProcessor requestProcessor,
                             IRouteConfigurator routeConfigurator, IAccessValidator accessValidator,
                             Configuration configuration)
        {
            _serviceProvider   = serviceProvider;
            _requestProcessor  = requestProcessor;
            _routeConfigurator = routeConfigurator;
            _accessValidator   = accessValidator;
            _configuration     = configuration;
            var processors = new Dictionary <string, Func <RouteConfig, Func <HttpRequest, HttpResponse, RouteData, Task> > >
            {
                ["return_value"] = UseReturnValueAsync,
                ["downstream"]   = UseDownstreamAsync,
                ["dispatcher"]   = UseDispatcherAsync
            };

            _methods = new Dictionary <string, Action <IRouteBuilder, string, RouteConfig> >
            {
                ["get"] = (builder, path, routeConfig) =>
                          builder.MapGet(path, processors[routeConfig.Route.Use](routeConfig)),
                ["post"] = (builder, path, routeConfig) =>
                           builder.MapPost(path, processors[routeConfig.Route.Use](routeConfig)),
                ["put"] = (builder, path, routeConfig) =>
                          builder.MapPut(path, processors[routeConfig.Route.Use](routeConfig)),
                ["delete"] = (builder, path, routeConfig) =>
                             builder.MapDelete(path, processors[routeConfig.Route.Use](routeConfig)),
                ["patch"] = (builder, path, routeConfig) =>
                            builder.MapVerb("patch", path, processors[routeConfig.Route.Use](routeConfig))
            };
            _extensions = LoadExtensions();
        }
Beispiel #3
0
 public static IRoute Options <TRequestController>(this IRouteConfigurator routeConfigurator,
                                                   string name, string path,
                                                   Controller <TRequestController> controller
                                                   ) where TRequestController : IRequestController
 {
     return(routeConfigurator.Add("OPTIONS", name, path, controller.Execute));
 }
Beispiel #4
0
 public static IRoute Patch <TRequestController>(this IRouteConfigurator routeConfigurator,
                                                 string name, string path,
                                                 Controller <TRequestController> controller
                                                 ) where TRequestController : IRequestController
 {
     return(routeConfigurator.Add("PATCH", name, path, controller.Execute));
 }
Beispiel #5
0
 public static IRoute Trace <TRequestController, TContent>(
     this IRouteConfigurator routeConfigurator,
     string name, string path,
     Controller <TRequestController, TContent> controller
     ) where TRequestController : IRequestController <TContent>
 {
     return(routeConfigurator.Add("TRACE", name, path, controller.Execute));
 }
Beispiel #6
0
        public static void EnableCorsOptionsRequestHandling(this IRouteConfigurator router,
                                                            Action <CorsOptions> setOptions = null)
        {
            router.Options("cors_preflight", "*", context =>
            {
                return(Task.Run(() =>
                                context.Response.SetCorsHeaders(CorsOptions.GetCorsOptions(setOptions))));
            });

            router.Options("cors_preflight", "/", context =>
            {
                return(Task.Run(() =>
                                context.Response.SetCorsHeaders(CorsOptions.GetCorsOptions(setOptions))));
            });
        }
Beispiel #7
0
 public RouteProvider(NtradaOptions options, IRequestHandlerManager requestHandlerManager,
                      IRouteConfigurator routeConfigurator, IRequestExecutionValidator requestExecutionValidator,
                      IUpstreamBuilder upstreamBuilder, WebApiEndpointDefinitions definitions, ILogger <RouteProvider> logger)
 {
     _routeConfigurator         = routeConfigurator;
     _requestExecutionValidator = requestExecutionValidator;
     _upstreamBuilder           = upstreamBuilder;
     _definitions           = definitions;
     _options               = options;
     _requestHandlerManager = requestHandlerManager;
     _logger  = logger;
     _methods = new Dictionary <string, Action <IEndpointRouteBuilder, string, RouteConfig> >
     {
         ["get"] = (builder, path, routeConfig) =>
                   builder.MapGet(path, ctx => Handle(ctx, routeConfig)),
         ["post"] = (builder, path, routeConfig) =>
                    builder.MapPost(path, ctx => Handle(ctx, routeConfig)),
         ["put"] = (builder, path, routeConfig) =>
                   builder.MapPut(path, ctx => Handle(ctx, routeConfig)),
         ["delete"] = (builder, path, routeConfig) =>
                      builder.MapDelete(path, ctx => Handle(ctx, routeConfig)),
     };
 }
Beispiel #8
0
 public static IRoute Patch(this IRouteConfigurator routeConfigurator, string name, string path,
                            RouteFuncAsync handler)
 {
     return(routeConfigurator.Add("PATCH", name, path, handler));
 }
 public MvcConfiguration(IRouteConfigurator routeConfigurator, IControllerFactory controllerFactory)
 {
     this.routeConfigurator = routeConfigurator;
     this.controllerFactory = controllerFactory;
 }
Beispiel #10
0
 public static IRoute Trace(this IRouteConfigurator routeConfigurator, string name, string path,
                            RouteFuncAsync handler)
 {
     return(routeConfigurator.Add("TRACE", name, path, handler));
 }
Beispiel #11
0
 public static IRoute Options(this IRouteConfigurator routeConfigurator, string name,
                              string path,
                              RouteFuncAsync handler)
 {
     return(routeConfigurator.Add("OPTIONS", name, path, handler));
 }
Beispiel #12
0
 public static IRoute Connect(this IRouteConfigurator routeConfigurator, string name,
                              string path,
                              RouteFuncAsync handler)
 {
     return(routeConfigurator.Add("CONNECT", name, path, handler));
 }
Beispiel #13
0
 public static IRoute Delete(this IRouteConfigurator routeConfigurator, string name, string path,
                             RouteFuncAsync handler)
 {
     return(routeConfigurator.Add("DELETE", name, path, handler));
 }
Beispiel #14
0
 public static IRoute Head(this IRouteConfigurator routeConfigurator, string name, string path,
                           RouteFuncAsync handler)
 {
     return(routeConfigurator.Add("HEAD", name, path, handler));
 }