Skip to content

Commit

Permalink
add target framework net8. (#1948)
Browse files Browse the repository at this point in the history
* Add target framework net 8.
* Obsolete serialize constructor for net 8.
* Apply `HttpConnectionDispatcherOptions.AllowStatefulReconnects`.
* Add net 8 in action.
  • Loading branch information
vwxyzh authored May 29, 2024
1 parent 26637e7 commit 89f3930
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: macOS-latest
strategy:
matrix:
dotnet-version: [ '7.0.x', '6.0.x' ]
dotnet-version: [ '8.0.x', '7.0.x', '6.0.x' ]
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
run: dotnet --version
- name: Build with dotnet
run: |
if [ "${{ matrix.dotnet-version }}" = "7.0.x" ]; then
if [ "${{ matrix.dotnet-version }}" != "6.0.x" ]; then
dotnet sln AzureSignalR.sln remove test/Microsoft.Azure.SignalR.Protocols.Tests/Microsoft.Azure.SignalR.Protocols.Tests.csproj
dotnet sln AzureSignalR.sln remove test/Microsoft.Azure.SignalR.Emulator.Tests/Microsoft.Azure.SignalR.Emulator.Tests.csproj
dotnet sln AzureSignalR.sln remove test/Microsoft.Azure.SignalR.Management.Tests/Microsoft.Azure.SignalR.Management.Tests.csproj
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [ '7.0.x', '6.0.x' ]
dotnet-version: [ '8.0.x', '7.0.x', '6.0.x' ]
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: [windows-latest]
strategy:
matrix:
dotnet-version: [ '7.0.x', '6.0.x' ]
dotnet-version: [ '8.0.x', '7.0.x', '6.0.x' ]
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public AzureSignalRAccessTokenTooLongException() : base($"AccessToken must not b
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="ArgumentNullException">The <paramref name="info"/> parameter is <c>null</c>.</exception>
/// <exception cref="SerializationException">The class name is <c>null</c> or <see cref="Exception.HResult"/> is zero (0).</exception>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected AzureSignalRAccessTokenTooLongException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public AzureSignalRConfigurationNoEndpointException() : base("No connection stri
{
}

#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected AzureSignalRConfigurationNoEndpointException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public AzureSignalRException(string message, Exception ex) : base(message, ex)
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="ArgumentNullException">The <paramref name="info"/> parameter is <c>null</c>.</exception>
/// <exception cref="SerializationException">The class name is <c>null</c> or <see cref="Exception.HResult"/> is zero (0).</exception>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected AzureSignalRException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public AzureSignalRInaccessibleEndpointException(string requestUri, Exception in
{
}

#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected AzureSignalRInaccessibleEndpointException(SerializationInfo info, StreamingContext context): base(info, context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public AzureSignalRInvalidArgumentException(string requestUri, Exception innerEx
{
}

#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected AzureSignalRInvalidArgumentException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public AzureSignalRInvalidServiceOptionsException(string propertyName, string va
{
}

#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected AzureSignalRInvalidServiceOptionsException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public AzureSignalRNoEndpointAvailableException() : base("No Azure Service endpo
{
}

#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected AzureSignalRNoEndpointAvailableException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public AzureSignalRNoPrimaryEndpointException() : base("No primary endpoint defi
{
}

#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected AzureSignalRNoPrimaryEndpointException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public AzureSignalRNotConnectedException() : base("Azure SignalR Service is not
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
/// <exception cref="ArgumentNullException">The <paramref name="info"/> parameter is <c>null</c>.</exception>
/// <exception cref="SerializationException">The class name is <c>null</c> or <see cref="Exception.HResult"/> is zero (0).</exception>
#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected AzureSignalRNotConnectedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public AzureSignalRRuntimeException(string requestUri, Exception innerException)
{
}

#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected AzureSignalRRuntimeException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ internal AzureSignalRUnauthorizedException(Exception innerException) : base(Erro
{
}

#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected AzureSignalRUnauthorizedException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public FailedWritingMessageToServiceException(string endpointUri) : base($"Unabl
EndpointUri = endpointUri;
}

#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected FailedWritingMessageToServiceException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public ServiceConnectionNotActiveException(string message) : base(string.IsNullO

}

#if NET8_0_OR_GREATER
[Obsolete]
#endif
protected ServiceConnectionNotActiveException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
48 changes: 45 additions & 3 deletions src/Microsoft.Azure.SignalR/HubHost/ServiceHubDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;


#if NET8_0_OR_GREATER
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Http.Connections;
#endif

namespace Microsoft.Azure.SignalR
{
internal class ServiceHubDispatcher<THub> where THub : Hub
Expand All @@ -32,6 +38,9 @@ internal class ServiceHubDispatcher<THub> where THub : Hub
private readonly IServiceEventHandler _serviceEventHandler;
private readonly IClientInvocationManager _clientInvocationManager;
private readonly IHubProtocolResolver _hubProtocolResolver;
#if NET8_0_OR_GREATER
private readonly HttpConnectionDispatcherOptions _dispatcherOptions;
#endif

protected readonly IServerNameProvider _nameProvider;

Expand All @@ -49,7 +58,12 @@ public ServiceHubDispatcher(
IClientConnectionFactory clientConnectionFactory,
IClientInvocationManager clientInvocationManager,
IServiceEventHandler serviceEventHandler,
IHubProtocolResolver hubProtocolResolver)
IHubProtocolResolver hubProtocolResolver
#if NET8_0_OR_GREATER
,
EndpointDataSource endpointDataSource
#endif
)
{
_serviceProtocol = serviceProtocol;
_serviceConnectionManager = serviceConnectionManager;
Expand All @@ -70,7 +84,30 @@ public ServiceHubDispatcher(

serverLifetimeManager?.Register(ShutdownAsync);
_hubProtocolResolver = hubProtocolResolver;
#if NET8_0_OR_GREATER
_dispatcherOptions = GetDispatcherOptions(endpointDataSource, typeof(THub));
#endif
}

#if NET8_0_OR_GREATER
private static HttpConnectionDispatcherOptions GetDispatcherOptions(EndpointDataSource source, Type hubType)
{
foreach (var endpoint in source.Endpoints)
{
var metaData = endpoint.Metadata;
if (metaData.GetMetadata<HubMetadata>()?.HubType == hubType)
{
var options = metaData.GetMetadata<HttpConnectionDispatcherOptions>();
if (options != null)
{
return options;
}
}
}
// It's not expected to go here in production environment. Return a value for test.
return new();
}
#endif

public void Start(ConnectionDelegate connectionDelegate, Action<HttpContext> contextConfig = null)
{
Expand Down Expand Up @@ -147,7 +184,7 @@ internal virtual ServiceConnectionFactory GetServiceConnectionFactory(
ConnectionFactory connectionFactory,
ConnectionDelegate connectionDelegate,
Action<HttpContext> contextConfig)
{
{
return new ServiceConnectionFactory(
_serviceProtocol,
_clientConnectionManager,
Expand All @@ -163,7 +200,12 @@ internal virtual ServiceConnectionFactory GetServiceConnectionFactory(
ConfigureContext = contextConfig,
ShutdownMode = _options.GracefulShutdown.Mode,
// todo: read per hub configuration from HttpConnectionDispatcherOptions.AllowStatefulReconnects for net 8.
AllowStatefulReconnects = _options.AllowStatefulReconnects ?? false,
AllowStatefulReconnects = _options.AllowStatefulReconnects ??
#if NET8_0_OR_GREATER
_dispatcherOptions.AllowStatefulReconnects,
#else
false,
#endif
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Azure.SignalR/Microsoft.Azure.SignalR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 89f3930

Please sign in to comment.