Skip to content

Commit 4f874d6

Browse files
authored
Merge pull request #26 from tpeczek/aspnetcore-v3.0.0
Support for ASP.NET Core 3.0.0. Resolves #25
2 parents 11c0ff2 + efaf37d commit 4f874d6

File tree

10 files changed

+136
-71
lines changed

10 files changed

+136
-71
lines changed

Benchmark.AspNetCore.ServerSentEvents/Benchmark.AspNetCore.ServerSentEvents.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.1</TargetFramework>
3+
<TargetFramework>netcoreapp3.0</TargetFramework>
44
</PropertyGroup>
55
<ItemGroup>
66
<None Remove="log.txt" />
@@ -9,7 +9,9 @@
99
<Folder Include="wwwroot\" />
1010
</ItemGroup>
1111
<ItemGroup>
12-
<PackageReference Include="docfx.console" Version="2.36.2" />
13-
<PackageReference Include="Microsoft.AspNetCore.All" />
12+
<PackageReference Include="docfx.console" Version="2.45.1">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
1416
</ItemGroup>
1517
</Project>
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
using Microsoft.AspNetCore;
2-
using Microsoft.AspNetCore.Hosting;
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
33

44
namespace DocFx.AspNetCore.ServerSentEvents
55
{
66
public class Program
77
{
8-
public static void Main(string[] args) => WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().Build().Run();
8+
public static void Main(string[] args)
9+
{
10+
CreateHostBuilder(args).Build().Run();
11+
}
12+
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args)
15+
.ConfigureWebHostDefaults(webBuilder =>
16+
{
17+
webBuilder.UseStartup<Startup>();
18+
});
919
}
1020
}

DocFx.AspNetCore.ServerSentEvents/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Microsoft.AspNetCore.Builder;
2-
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
33
using Microsoft.Extensions.DependencyInjection;
44

55
namespace DocFx.AspNetCore.ServerSentEvents
@@ -9,7 +9,7 @@ public class Startup
99
public void ConfigureServices(IServiceCollection services)
1010
{ }
1111

12-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
12+
public void Configure(IApplicationBuilder app, IHostEnvironment env)
1313
{
1414
app.UseDefaultFiles()
1515
.UseStaticFiles();

DocFx.AspNetCore.ServerSentEvents/docfx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"dest": "api",
1414
"properties": {
15-
"TargetFramework": "netstandard2.0"
15+
"TargetFramework": "netcoreapp3.0"
1616
}
1717
}
1818
],

Lib.AspNetCore.ServerSentEvents/Lib.AspNetCore.ServerSentEvents.csproj

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
<PropertyGroup>
33
<Description>Lib.AspNetCore.ServerSentEvents is a library which provides Server-Sent Events (SSE) support for ASP.NET Core</Description>
44
<Copyright>Copyright © 2017 - 2019 Tomasz Pęczek</Copyright>
5-
<VersionPrefix>3.3.0</VersionPrefix>
5+
<VersionPrefix>4.0.0</VersionPrefix>
6+
<VersionSuffix>preview3</VersionSuffix>
67
<Authors>Tomasz Pęczek</Authors>
7-
<TargetFramework>netstandard2.0</TargetFramework>
8+
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0;net461</TargetFrameworks>
89
<AssemblyTitle>Lib.AspNetCore.ServerSentEvents</AssemblyTitle>
910
<AssemblyName>Lib.AspNetCore.ServerSentEvents</AssemblyName>
1011
<PackageId>Lib.AspNetCore.ServerSentEvents</PackageId>
1112
<PackageTags>aspnetcore;sse;server-sent;events;eventsource</PackageTags>
1213
<PackageProjectUrl>https://github.com/tpeczek/Lib.AspNetCore.ServerSentEvents</PackageProjectUrl>
13-
<PackageLicenseUrl>https://github.com/tpeczek/Lib.AspNetCore.ServerSentEvents/blob/master/LICENSE.md</PackageLicenseUrl>
14+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1415
<RepositoryType>git</RepositoryType>
1516
<RepositoryUrl>git://github.com/tpeczek/Lib.AspNetCore.ServerSentEvents</RepositoryUrl>
1617
<GenerateAssemblyTitleAttribute>true</GenerateAssemblyTitleAttribute>
@@ -21,12 +22,15 @@
2122
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2223
<LangVersion>latest</LangVersion>
2324
</PropertyGroup>
24-
<ItemGroup>
25-
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.0.0" />
26-
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="2.0.0" />
27-
<PackageReference Include="Microsoft.AspNetCore.Authorization.Policy" Version="2.0.0" />
28-
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
29-
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.0.0" />
30-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.0.0" />
25+
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.0'">
26+
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="[2.1.0,3.0.0)" />
27+
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="[2.1.0,3.0.0)" />
28+
<PackageReference Include="Microsoft.AspNetCore.Authorization.Policy" Version="[2.1.0,3.0.0)" />
29+
<PackageReference Include="Microsoft.Extensions.Options" Version="[2.1.0,3.0.0)" />
30+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="[2.1.0,3.0.0)" />
31+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="[2.1.0,3.0.0)" />
32+
</ItemGroup>
33+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
34+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
3135
</ItemGroup>
3236
</Project>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#if NETCOREAPP3_0
2+
using System;
3+
using Microsoft.AspNetCore.Http;
4+
using Microsoft.AspNetCore.Builder;
5+
using Microsoft.AspNetCore.Routing;
6+
7+
namespace Lib.AspNetCore.ServerSentEvents
8+
{
9+
/// <summary>
10+
/// Provides extension methods for <see cref="IEndpointRouteBuilder"/> to add Server-Sent Events.
11+
/// </summary>
12+
public static class ServerSentEventsEndpointRouteBuilderExtensions
13+
{
14+
#region Fields
15+
private const string DEFAULT_DISPLAY_NAME = "Server-Sent Events";
16+
#endregion
17+
18+
#region Methods
19+
/// <summary>
20+
/// Adds a Server-Sent Events endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template.
21+
/// </summary>
22+
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the Server-Sent Events endpoint to.</param>
23+
/// <param name="pattern">The URL pattern of the Server-Sent Events endpoint.</param>
24+
/// <returns>A convention routes for the Server-Sent Events endpoint.</returns>
25+
public static IEndpointConventionBuilder MapServerSentEvents(this IEndpointRouteBuilder endpoints, string pattern)
26+
{
27+
return endpoints.MapServerSentEvents<ServerSentEventsService>(pattern);
28+
}
29+
30+
/// <summary>
31+
/// Adds a Server-Sent Events endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template and options.
32+
/// </summary>
33+
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the Server-Sent Events endpoint to.</param>
34+
/// <param name="pattern">The URL pattern of the Server-Sent Events endpoint.</param>
35+
/// <param name="options">A <see cref="ServerSentEventsOptions"/> used to configure the Server-Sent Events.</param>
36+
/// <returns>A convention routes for the Server-Sent Events endpoint.</returns>
37+
public static IEndpointConventionBuilder MapServerSentEvents(this IEndpointRouteBuilder endpoints, string pattern, ServerSentEventsOptions options)
38+
{
39+
return endpoints.MapServerSentEvents<ServerSentEventsService>(pattern, options);
40+
}
41+
42+
/// <summary>
43+
/// Adds a Server-Sent Events endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template.
44+
/// </summary>
45+
/// <typeparam name="TServerSentEventsService">The type of custom <see cref="ServerSentEventsService"/>.</typeparam>
46+
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the Server-Sent Events endpoint to.</param>
47+
/// <param name="pattern">The URL pattern of the Server-Sent Events endpoint.</param>
48+
/// <returns>A convention routes for the Server-Sent Events endpoint.</returns>
49+
public static IEndpointConventionBuilder MapServerSentEvents<TServerSentEventsService>(this IEndpointRouteBuilder endpoints, string pattern)
50+
where TServerSentEventsService : ServerSentEventsService
51+
{
52+
return endpoints.MapServerSentEvents<TServerSentEventsService>(pattern, new ServerSentEventsOptions());
53+
}
54+
55+
/// <summary>
56+
/// Adds a Server-Sent Events endpoint to the <see cref="IEndpointRouteBuilder"/> with the specified template and options.
57+
/// </summary>
58+
/// <typeparam name="TServerSentEventsService">The type of custom <see cref="ServerSentEventsService"/>.</typeparam>
59+
/// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the Server-Sent Events endpoint to.</param>
60+
/// <param name="pattern">The URL pattern of the Server-Sent Events endpoint.</param>
61+
/// <param name="options">A <see cref="ServerSentEventsOptions"/> used to configure the Server-Sent Events.</param>
62+
/// <returns>A convention routes for the Server-Sent Events endpoint.</returns>
63+
public static IEndpointConventionBuilder MapServerSentEvents<TServerSentEventsService>(this IEndpointRouteBuilder endpoints, string pattern, ServerSentEventsOptions options)
64+
where TServerSentEventsService : ServerSentEventsService
65+
{
66+
if (endpoints == null)
67+
{
68+
throw new ArgumentNullException(nameof(endpoints));
69+
}
70+
71+
if (options == null)
72+
{
73+
throw new ArgumentNullException(nameof(options));
74+
}
75+
76+
RequestDelegate pipeline = endpoints.CreateApplicationBuilder()
77+
.UseServerSentEvents<TServerSentEventsService>(options)
78+
.Build();
79+
80+
return endpoints.Map(pattern, pipeline).WithDisplayName(DEFAULT_DISPLAY_NAME);
81+
}
82+
#endregion
83+
}
84+
}
85+
#endif

Lib.AspNetCore.ServerSentEvents/ServerSentEventsMiddleware.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,19 @@ private async Task ForbidAsync(HttpContext context)
151151

152152
private void DisableResponseBuffering(HttpContext context)
153153
{
154+
#if NETCOREAPP3_0
155+
IHttpResponseBodyFeature responseBodyFeature = context.Features.Get<IHttpResponseBodyFeature>();
156+
if (responseBodyFeature != null)
157+
{
158+
responseBodyFeature.DisableBuffering();
159+
}
160+
#else
154161
IHttpBufferingFeature bufferingFeature = context.Features.Get<IHttpBufferingFeature>();
155162
if (bufferingFeature != null)
156163
{
157164
bufferingFeature.DisableResponseBuffering();
158165
}
166+
#endif
159167
}
160168

161169
private void HandleContentEncoding(HttpContext context)

Lib.AspNetCore.ServerSentEvents/ServerSentEventsMiddlewareExtensions.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -209,50 +209,5 @@ public static IApplicationBuilder MapServerSentEvents<TServerSentEventsService>(
209209
return app.Map(pathMatch, branchedApp => branchedApp.UseServerSentEvents<TServerSentEventsService>(options));
210210
}
211211
#endregion
212-
213-
#region Obsolete Methods
214-
/// <summary>
215-
/// Adds the middleware which provides support for Server-Sent Events protocol to the pipeline with custom service.
216-
/// </summary>
217-
/// <param name="app">The pipeline builder.</param>
218-
/// <param name="serverSentEventsService">The custom service.</param>
219-
/// <returns>The pipeline builder.</returns>
220-
[Obsolete("This method will soon be removed. Use UseServerSentEvents<TServerSentEventsService> instead.")]
221-
public static IApplicationBuilder UseServerSentEvents(this IApplicationBuilder app, ServerSentEventsService serverSentEventsService)
222-
{
223-
if (app == null)
224-
{
225-
throw new ArgumentNullException(nameof(app));
226-
}
227-
228-
if (serverSentEventsService == null)
229-
{
230-
throw new ArgumentNullException(nameof(serverSentEventsService));
231-
}
232-
233-
Type serverSentEventsServiceType = serverSentEventsService.GetType();
234-
Type serverSentEventsMiddlewareType = typeof(ServerSentEventsMiddleware<>).MakeGenericType(serverSentEventsServiceType);
235-
236-
return app.UseMiddleware(serverSentEventsMiddlewareType, Options.Create(new ServerSentEventsOptions()));
237-
}
238-
239-
/// <summary>
240-
/// Adds the middleware which provides support for Server-Sent Events protocol to the branch of pipeline with custom service.
241-
/// </summary>
242-
/// <param name="app">The pipeline builder.</param>
243-
/// <param name="pathMatch">The request path to match.</param>
244-
/// <param name="serverSentEventsService">The custom service.</param>
245-
/// <returns>The pipeline builder.</returns>
246-
[Obsolete("This method will soon be removed. Use MapServerSentEvents<TServerSentEventsService> instead.")]
247-
public static IApplicationBuilder MapServerSentEvents(this IApplicationBuilder app, PathString pathMatch, ServerSentEventsService serverSentEventsService)
248-
{
249-
if (app == null)
250-
{
251-
throw new ArgumentNullException(nameof(app));
252-
}
253-
254-
return app.Map(pathMatch, branchedApp => branchedApp.UseServerSentEvents(serverSentEventsService));
255-
}
256-
#endregion
257212
}
258213
}

Test.AspNetCore.ServerSentEvents/Test.AspNetCore.ServerSentEvents.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.2</TargetFramework>
3+
<TargetFramework>netcoreapp3.0</TargetFramework>
44
<IsPackable>false</IsPackable>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
8-
<PackageReference Include="Moq" Version="4.10.1" />
7+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0-preview-20190828-03" />
8+
<PackageReference Include="Moq" Version="4.13.0" />
99
<PackageReference Include="xunit" Version="2.4.1" />
1010
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1313
</PackageReference>
14-
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.0.0" />
15-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
14+
</ItemGroup>
15+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
16+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
1617
</ItemGroup>
1718
<ItemGroup>
1819
<ProjectReference Include="..\Lib.AspNetCore.ServerSentEvents\Lib.AspNetCore.ServerSentEvents.csproj" />

0 commit comments

Comments
 (0)