/// <summary> /// Initializes new instance of middleware. /// </summary> /// <param name="next">The next delegate in the pipeline.</param> /// <param name="policyProvider">The service which can provide an <see cref="AuthorizationPolicy" />.</param> /// <param name="serverSentEventsService">The service which provides operations over Server-Sent Events protocol.</param> /// <param name="serverSentEventsOptions"></param> public ServerSentEventsMiddleware(RequestDelegate next, IAuthorizationPolicyProvider policyProvider, TServerSentEventsService serverSentEventsService, IOptions <ServerSentEventsOptions> serverSentEventsOptions) { _next = next ?? throw new ArgumentNullException(nameof(next)); _policyProvider = policyProvider ?? throw new ArgumentNullException(nameof(policyProvider)); _serverSentEventsService = serverSentEventsService ?? throw new ArgumentNullException(nameof(serverSentEventsService)); _serverSentEventsOptions = serverSentEventsOptions?.Value ?? throw new ArgumentNullException(nameof(serverSentEventsOptions)); }
/// <summary> /// Adds a Server-Sent Events endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template and options. /// </summary> /// <typeparam name="TServerSentEventsService">The type of custom <see cref="ServerSentEventsService"/>.</typeparam> /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the Server-Sent Events endpoint to.</param> /// <param name="pattern">The URL pattern of the Server-Sent Events endpoint.</param> /// <param name="options">A <see cref="ServerSentEventsOptions"/> used to configure the Server-Sent Events.</param> /// <returns>A convention routes for the Server-Sent Events endpoint.</returns> public static IEndpointConventionBuilder MapServerSentEvents <TServerSentEventsService>(this IEndpointRouteBuilder endpoints, string pattern, ServerSentEventsOptions options) where TServerSentEventsService : ServerSentEventsService { if (endpoints == null) { throw new ArgumentNullException(nameof(endpoints)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } RequestDelegate pipeline = endpoints.CreateApplicationBuilder() .UseServerSentEvents <TServerSentEventsService>(options) .Build(); return(endpoints.Map(pattern, pipeline).WithDisplayName(DEFAULT_DISPLAY_NAME)); }
/// <summary> /// Adds a Server-Sent Events endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template and options. /// </summary> /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the Server-Sent Events endpoint to.</param> /// <param name="pattern">The URL pattern of the Server-Sent Events endpoint.</param> /// <param name="options">A <see cref="ServerSentEventsOptions"/> used to configure the Server-Sent Events.</param> /// <returns>A convention routes for the Server-Sent Events endpoint.</returns> public static IEndpointConventionBuilder MapServerSentEvents(this IEndpointRouteBuilder endpoints, string pattern, ServerSentEventsOptions options) { return(endpoints.MapServerSentEvents <ServerSentEventsService>(pattern, options)); }
/// <summary> /// Adds the middleware which provides support for Server-Sent Events protocol to the branch of pipeline with custom service. /// </summary> /// <typeparam name="TServerSentEventsService">The type of custom <see cref="ServerSentEventsService"/>.</typeparam> /// <param name="app">The pipeline builder.</param> /// <param name="pathMatch">The request path to match.</param> /// <param name="options">The options.</param> /// <returns>The pipeline builder.</returns> public static IApplicationBuilder MapServerSentEvents <TServerSentEventsService>(this IApplicationBuilder app, PathString pathMatch, ServerSentEventsOptions options) where TServerSentEventsService : ServerSentEventsService { if (app == null) { throw new ArgumentNullException(nameof(app)); } return(app.Map(pathMatch, branchedApp => branchedApp.UseServerSentEvents <TServerSentEventsService>(options))); }
/// <summary> /// Adds the middleware which provides support for Server-Sent Events protocol to the pipeline with custom service. /// </summary> /// <typeparam name="TServerSentEventsService">The type of custom <see cref="ServerSentEventsService"/>.</typeparam> /// <param name="app">The pipeline builder.</param> /// <param name="options">The options.</param> /// <returns>The pipeline builder.</returns> public static IApplicationBuilder UseServerSentEvents <TServerSentEventsService>(this IApplicationBuilder app, ServerSentEventsOptions options) where TServerSentEventsService : ServerSentEventsService { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return(app.UseMiddleware <ServerSentEventsMiddleware <TServerSentEventsService> >(Options.Create(options))); }
/// <summary> /// Adds the middleware which provides support for Server-Sent Events protocol to the pipeline with default service. /// </summary> /// <param name="app">The pipeline builder.</param> /// <param name="options">The options.</param> /// <returns>The pipeline builder.</returns> public static IApplicationBuilder UseServerSentEvents(this IApplicationBuilder app, ServerSentEventsOptions options) { return(app.UseServerSentEvents <ServerSentEventsService>(options)); }