public static IApplicationBuilder MapServerSentEvents(this IApplicationBuilder app, PathString pathMatch, ServerSentEventsService serverSentEventsService) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (serverSentEventsService == null) { throw new ArgumentNullException(nameof(serverSentEventsService)); } return(app.Map(pathMatch, branchedApp => branchedApp.UseServerSentEvents(serverSentEventsService))); }
/// <summary> /// Initializes new instance of middleware. /// </summary> /// <param name="next">The next delegate in the pipeline.</param> /// <param name="serverSentEventsService">The service which provides operations over Server-Sent Events protocol.</param> public ServerSentEventsMiddleware(RequestDelegate next, ServerSentEventsService serverSentEventsService) { _next = next ?? throw new ArgumentNullException(nameof(next)); _serverSentEventsService = serverSentEventsService ?? throw new ArgumentNullException(nameof(serverSentEventsService)); }
public static IApplicationBuilder UseServerSentEvents(this IApplicationBuilder app, ServerSentEventsService serverSentEventsService) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (serverSentEventsService == null) { throw new ArgumentNullException(nameof(serverSentEventsService)); } Type serverSentEventsServiceType = serverSentEventsService.GetType(); Type serverSentEventsMiddlewareType = typeof(ServerSentEventsMiddleware <>).MakeGenericType(serverSentEventsServiceType); return(app.UseMiddleware(serverSentEventsMiddlewareType)); }
/// <summary> /// Adds the middleware which provides support for Server-Sent Events protocol to the pipeline with custom service. /// </summary> /// <param name="app">The pipeline builder.</param> /// <param name="serverSentEventsService">The custom service.</param> /// <returns>The pipeline builder.</returns> public static IApplicationBuilder UseServerSentEvents(this IApplicationBuilder app, ServerSentEventsService serverSentEventsService) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (serverSentEventsService == null) { throw new ArgumentNullException(nameof(serverSentEventsService)); } return(app.UseMiddleware <ServerSentEventsMiddleware>(serverSentEventsService)); }