public IEndpoint CreateEndpoint(Uri requestedUri) { string scheme = requestedUri.Scheme.ToLowerInvariant(); if (_transportFactories.Has(scheme)) { ITransportFactory transportFactory = _transportFactories[scheme]; try { IEndpointAddress address = transportFactory.GetAddress(requestedUri); var uriPath = new Uri(address.Uri.GetLeftPart(UriPartial.Path)); IEndpointBuilder builder = _endpointBuilders.Get(uriPath, key => { var configurator = new EndpointConfigurator(address, _defaults); return(configurator.CreateBuilder()); }); return(builder.CreateEndpoint(transportFactory)); } catch (Exception ex) { throw new EndpointException(requestedUri, "Failed to create endpoint", ex); } } throw new ConfigurationException( "The {0} scheme was not handled by any registered transport.".FormatWith(requestedUri.Scheme)); }
public override void RegisterEndpoints(IEndpointBuilder endpoints) { endpoints.MapControllers(); endpoints.MapApiDocument( name: "sample", title: "Sample Module", description: "The API for sample module", version: "1.0"); endpoints.WithErrorHandler("Sample", "Main") .MapFallbackNotFound("/sample/{**slug}") .MapStatusCode("/sample/{**slug}") .MapFallbackNotFound("/route-test/{id:int}") .MapFallbackNotFound("/route-test/{id:alpha}"); endpoints.MapRequestDelegate("/weather/checker", async context => { await context.Response.WriteAsync("Hello World!"); }); endpoints.MapRequestDelegate("/sample/world", context => { context.Response.StatusCode = 402; return(Task.CompletedTask); }); }
public DefaultRequestHandler(IOptions <SimpleS3Config> options, IRequestValidatorFactory validator, IMarshalFactory marshaller, IPostMapperFactory postMapper, INetworkDriver networkDriver, HeaderAuthorizationBuilder authBuilder, IEndpointBuilder endpointBuilder, ILogger <DefaultRequestHandler> logger, IEnumerable <IRequestStreamWrapper>?requestStreamWrappers = null) { Validator.RequireNotNull(options, nameof(options)); Validator.RequireNotNull(validator, nameof(validator)); Validator.RequireNotNull(marshaller, nameof(marshaller)); Validator.RequireNotNull(networkDriver, nameof(networkDriver)); Validator.RequireNotNull(authBuilder, nameof(authBuilder)); Validator.RequireNotNull(logger, nameof(logger)); _requestValidator = validator; _config = options.Value; _networkDriver = networkDriver; _authBuilder = authBuilder; _endpointBuilder = endpointBuilder; _marshaller = marshaller; _postMapper = postMapper; _logger = logger; if (requestStreamWrappers == null) { _requestStreamWrappers = Array.Empty <IRequestStreamWrapper>(); } else { _requestStreamWrappers = requestStreamWrappers.ToList(); } }
public void Map(IEndpointBuilder <TContext> endpointBuilder) { // persist a copy of the current predicate stack in endpoint builder endpointBuilder.Requires(_predicateStack.ToArray()); _endpointRoutes.Add(new EndpointRoute <TContext>(Array.Empty <Predicate <TContext> >(), endpointBuilder)); }
public IEndpointFactoryBuilder Configure(IEndpointFactoryBuilder builder) { IEndpointBuilder endpointBuilder = CreateBuilder(); builder.AddEndpointBuilder(_baseUri, endpointBuilder); return(builder); }
public override void RegisterEndpoints(IEndpointBuilder endpoints) { endpoints.MapControllers(); endpoints.MapFallNotFound("/api/{**slug}"); endpoints.MapFallNotFound("/lib/{**slug}"); endpoints.MapFallNotFound("/images/{**slug}"); endpoints.WithErrorHandler("Dashboard", "Root") .MapStatusCode("/dashboard/{**slug}"); }
public override void RegisterEndpoints(IEndpointBuilder endpoints) { endpoints.MapControllers(); endpoints.MapFallback("/", context => { context.Response.Redirect("/dashboard/contests"); return(Task.CompletedTask); }); }
public override void RegisterEndpoints(IEndpointBuilder endpoints) { var options = endpoints.ServiceProvider.GetOptions <ApplicationInsightsDisplayOptions>(); if (string.IsNullOrEmpty(options.Value.ApiKey)) { return; } endpoints.MapControllers(); }
protected async Task <T> RetrieveAsync <T>(IEndpointBuilder builder, GW2RESTConfig config = null) { if (!string.IsNullOrEmpty(ApiKey)) { if (config == null || config.IgnoreAuthentication == false) { builder.AddParameter("access_token", ApiKey); } } string json = await retriever.GetJsonAsync(builder); return(deserializer.Deserialize <T>(json)); }
public DefaultSignedRequestHandler(IOptions <SimpleS3Config> options, IScopeBuilder scopeBuilder, IMarshalFactory marshaller, QueryParameterAuthorizationBuilder authBuilder, IEndpointBuilder endpointBuilder, ILogger <DefaultSignedRequestHandler> logger) { Validator.RequireNotNull(options, nameof(options)); Validator.RequireNotNull(marshaller, nameof(marshaller)); Validator.RequireNotNull(authBuilder, nameof(authBuilder)); Validator.RequireNotNull(logger, nameof(logger)); _config = options.Value; _authBuilder = authBuilder; _endpointBuilder = endpointBuilder; _marshaller = marshaller; _logger = logger; _scopeBuilder = scopeBuilder; }
public void Setup() { SimpleS3Config config = new SimpleS3Config(null !, "eu-west-1"); config.EndpointTemplate = "{Scheme}://{Bucket:.}s3.{Region:.}amazonaws.com"; SimpleS3Config config2 = new SimpleS3Config(null !, "eu-west-1"); config2.Endpoint = new Uri("http://bucket.s3.eu-west-1.amazonaws.com"); _builder = new EndpointBuilder(Options.Create(config)); _builder2 = new EndpointBuilder(Options.Create(config2)); _request = new GetObjectRequest("bucket", "object"); }
public static IEndpointBuilder ConfigureEndpoint(this IEndpointBuilder builder, Func <IServiceProvider, IEndpoint> createEndpoint) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (createEndpoint == null) { throw new ArgumentNullException(nameof(createEndpoint)); } builder.Services.Configure <EndpointFactoryOptions>(builder.Name, options => options.EndpointFuncs.Add(createEndpoint)); return(builder); }
public HealthChecker( IRouteDiscover aspNetRouteDiscover, IEndpointBuilder endpointBuilder, IAutoHealthCheckContextAccessor autoHealthCheckContextAccessor, IEndpointMessageTranslator endpointMessageTranslator, IEndpointCaller endpointCaller, IProbesProcessor probesProcessor) { _endpointBuilder = endpointBuilder; _autoHealthCheckContextAccessor = autoHealthCheckContextAccessor; _endpointMessageTranslator = endpointMessageTranslator; _endpointCaller = endpointCaller; _probesProcessor = probesProcessor; // route async _routesFactory = new AsyncLazy <IEnumerable <IRouteInformation> >(() => aspNetRouteDiscover.GetAllEndpoints()); }
/// <summary> /// Maps incoming requests with the specified path to the specified <see cref="Hub"/> type. /// </summary> /// <typeparam name="THub">The <see cref="Hub"/> type to map requests to.</typeparam> /// <param name="endpoints">The <see cref="IEndpointBuilder"/> to add the route to.</param> /// <param name="pattern">The route pattern.</param> /// <param name="configureOptions">A callback to configure dispatcher options.</param> /// <returns>An <see cref="HubEndpointConventionBuilder"/> for endpoints associated with the connections.</returns> public static HubEndpointConventionBuilder MapHub <THub>(this IEndpointBuilder endpoints, string pattern, Action <HttpConnectionDispatcherOptions>?configureOptions) where THub : Hub { var marker = endpoints.ServiceProvider.GetService(_signalRMarkerServiceType); if (marker == null) { throw new InvalidOperationException( "Unable to find the required services. Please add all the required services by calling " + "'IServiceCollection.AddSignalR' inside the call to 'ConfigureServices(...)' in the application startup code."); } var options = new HttpConnectionDispatcherOptions(); configureOptions?.Invoke(options); var conventionBuilder = endpoints.MapConnections(pattern, options, b => { b.UseHub <THub>(); }); var attributes = typeof(THub).GetCustomAttributes(inherit: true); conventionBuilder.Add(e => { // Add all attributes on the Hub as metadata (this will allow for things like) // auth attributes and cors attributes to work seamlessly foreach (var item in attributes) { e.Metadata.Add(item); } // Add metadata that captures the hub type this endpoint is associated with e.Metadata.Add(new HubMetadata(typeof(THub))); }); return((HubEndpointConventionBuilder) typeof(HubEndpointConventionBuilder) .GetTypeInfo().DeclaredConstructors .Single() .Invoke(new object[] { conventionBuilder })); }
public EndpointDispatcherBuilder(IEndpointBuilder builder) { _builder = builder ?? throw new ArgumentNullException(nameof(builder)); }
/// <summary> /// Maps incoming requests with the specified path to the provided connection pipeline. /// </summary> /// <param name="endpoints">The <see cref="IEndpointBuilder"/> to add the route to.</param> /// <param name="pattern">The route pattern.</param> /// <param name="options">Options used to configure the connection.</param> /// <param name="configure">A callback to configure the connection.</param> /// <returns>An <see cref="ConnectionEndpointRouteBuilder"/> for endpoints associated with the connections.</returns> public static ConnectionEndpointRouteBuilder MapConnections(this IEndpointBuilder endpoints, string pattern, HttpConnectionDispatcherOptions options, Action <IConnectionBuilder> configure) { var dispatcher = endpoints.ServiceProvider.GetRequiredService(_httpConnectionDispatcherType); var ExecuteNegotiateAsync = (Func <HttpContext, HttpConnectionDispatcherOptions, Task>) _httpConnectionDispatcherType .GetMethod("ExecuteNegotiateAsync") ! .CreateDelegate(typeof(Func <HttpContext, HttpConnectionDispatcherOptions, Task>), dispatcher); var ExecuteAsync = (Func <HttpContext, HttpConnectionDispatcherOptions, ConnectionDelegate, Task>) _httpConnectionDispatcherType .GetMethod("ExecuteAsync") ! .CreateDelegate(typeof(Func <HttpContext, HttpConnectionDispatcherOptions, ConnectionDelegate, Task>), dispatcher); var connectionBuilder = new ConnectionBuilder(endpoints.ServiceProvider); configure(connectionBuilder); var connectionDelegate = connectionBuilder.Build(); // REVIEW: Consider expanding the internals of the dispatcher as endpoint routes instead of // using if statements we can let the matcher handle var conventionBuilders = new List <IEndpointConventionBuilder>(); // Build the negotiate application var app = endpoints.CreateApplicationBuilder(); app.UseWebSockets(); app.Run(c => ExecuteNegotiateAsync(c, options)); var negotiateHandler = app.Build(); var negotiateBuilder = endpoints.MapRequestDelegate(pattern + "/negotiate", negotiateHandler); conventionBuilders.Add(negotiateBuilder); // Add the negotiate metadata so this endpoint can be identified negotiateBuilder.WithMetadata(new NegotiateMetadata()); // build the execute handler part of the protocol app = endpoints.CreateApplicationBuilder(); app.UseWebSockets(); app.Run(c => ExecuteAsync(c, options, connectionDelegate)); var executehandler = app.Build(); var executeBuilder = endpoints.MapRequestDelegate(pattern, executehandler); conventionBuilders.Add(executeBuilder); var compositeConventionBuilder = new CompositeEndpointConventionBuilder(conventionBuilders); // Add metadata to all of Endpoints compositeConventionBuilder.Add(e => { // Add the authorization data as metadata foreach (var data in options.AuthorizationData) { e.Metadata.Add(data); } }); return((ConnectionEndpointRouteBuilder) typeof(ConnectionEndpointRouteBuilder) .GetTypeInfo().DeclaredConstructors .Single() .Invoke(new object[] { compositeConventionBuilder })); }
public override void RegisterEndpoints(IEndpointBuilder endpoints) { endpoints.MapControllers(); }
public DefaultErrorHandlerBuilder(ControllerActionDescriptorWrapper actionDescriptor, IEndpointBuilder builder) { ActionDescriptor = actionDescriptor; Builder = builder; }
public override void RegisterEndpoints(IEndpointBuilder endpoints) { endpoints.MapBlazorHub(); }
public EndpointRoute(Predicate <TContext>[] predicates, IEndpointBuilder <TContext> endpointBuilder) { Predicates = predicates ?? throw new ArgumentNullException(nameof(predicates)); EndpointBuilder = endpointBuilder ?? throw new ArgumentNullException(nameof(endpointBuilder)); }
public void AddEndpointBuilder(Uri uri, IEndpointBuilder endpointBuilder) { _endpointBuilders[uri] = endpointBuilder; }
public string GetJson(IEndpointBuilder builder) { return(client.GetStringAsync(builder.Build()).Result); }
public async Task <string> GetJsonAsync(IEndpointBuilder builder) { return(await client.GetStringAsync(builder.Build())); }
/// <summary> /// Register the endpoints with some more configurations. /// </summary> /// <param name="endpoints">The endpoint route builder</param> public virtual void RegisterEndpoints(IEndpointBuilder endpoints) { }
/// <summary> /// Maps incoming requests with the specified path to the provided connection pipeline. /// </summary> /// <typeparam name="TConnectionHandler">The <see cref="ConnectionHandler"/> type.</typeparam> /// <param name="endpoints">The <see cref="IEndpointBuilder"/> to add the route to.</param> /// <param name="pattern">The route pattern.</param> /// <param name="configureOptions">A callback to configure dispatcher options.</param> /// <returns>An <see cref="ConnectionEndpointRouteBuilder"/> for endpoints associated with the connections.</returns> public static ConnectionEndpointRouteBuilder MapConnectionHandler <TConnectionHandler>(this IEndpointBuilder endpoints, string pattern, Action <HttpConnectionDispatcherOptions>?configureOptions) where TConnectionHandler : ConnectionHandler { var options = new HttpConnectionDispatcherOptions(); configureOptions?.Invoke(options); var conventionBuilder = endpoints.MapConnections(pattern, options, b => { b.UseConnectionHandler <TConnectionHandler>(); }); var attributes = typeof(TConnectionHandler).GetCustomAttributes(inherit: true); conventionBuilder.Add(e => { // Add all attributes on the ConnectionHandler has metadata (this will allow for things like) // auth attributes and cors attributes to work seamlessly foreach (var item in attributes) { e.Metadata.Add(item); } }); return(conventionBuilder); }