Skip to content

Commit

Permalink
Merge pull request #3614 from rockfordlhotka/v8-stuff
Browse files Browse the repository at this point in the history
Updates for .NET 8
  • Loading branch information
rockfordlhotka authored Dec 18, 2023
2 parents 5cec8c4 + 056b6ee commit 6d159d2
Show file tree
Hide file tree
Showing 42 changed files with 138 additions and 457 deletions.
4 changes: 2 additions & 2 deletions NuGet/Definition/Csla.AspNetCore.NuSpec
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</group>
<group targetFramework="net8.0">
<dependency id="Csla" version="[4.6.3-Beta10]" />
<dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.0-rc.1.23419.4" />
<dependency id="Microsoft.AspNetCore.Components.Authorization" version="8.0.0-rc.1.23421.29" />
<dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.0" />
<dependency id="Microsoft.AspNetCore.Components.Authorization" version="8.0.0" />
</group>
</dependencies>
</metadata>
Expand Down
6 changes: 3 additions & 3 deletions NuGet/Definition/Csla.Blazor.NuSpec
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
</group>
<group targetFramework="net8.0">
<dependency id="Csla" version="[4.6.3-Beta10]" />
<dependency id="Microsoft.AspNetCore.Components" version="8.0.0-rc.1.23421.29" />
<dependency id="Microsoft.AspNetCore.Components.Web" version="8.0.0-rc.1.23421.29" />
<dependency id="Microsoft.AspNetCore.Components.Authorization" version="8.0.0-rc.1.23421.29" />
<dependency id="Microsoft.AspNetCore.Components" version="8.0.0" />
<dependency id="Microsoft.AspNetCore.Components.Web" version="8.0.0" />
<dependency id="Microsoft.AspNetCore.Components.Authorization" version="8.0.0" />
</group>
</dependencies>
</metadata>
Expand Down
2 changes: 1 addition & 1 deletion NuGet/Definition/Csla.Blazor.WebAssembly.NuSpec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<group targetFramework="net8.0">
<dependency id="Csla" version="[4.6.3-Beta10]" />
<dependency id="Csla.Blazor" version="[4.6.3-Beta10]" />
<dependency id="Microsoft.AspNetCore.Components.WebAssembly" version="8.0.0-rc.1.23421.29" />
<dependency id="Microsoft.AspNetCore.Components.WebAssembly" version="8.0.0" />
<dependency id="System.Net.Http.Json" version="7.0.1" />
</group>
</dependencies>
Expand Down
12 changes: 6 additions & 6 deletions NuGet/Definition/Csla.NuSpec
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@
<dependency id="System.Runtime.Loader" version="4.3.0" />
</group>
<group targetFramework="net8.0">
<dependency id="Microsoft.Extensions.Configuration" version="8.0.0-rc.1.23419.4" />
<dependency id="Microsoft.Extensions.Configuration.Binder" version="8.0.0-rc.1.23419.4" />
<dependency id="Microsoft.Extensions.DependencyInjection" version="8.0.0-rc.1.23419.4" />
<dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.0-rc.1.23419.4" />
<dependency id="Microsoft.Extensions.Hosting.Abstractions" version="8.0.0-rc.1.23419.4" />
<dependency id="Microsoft.Extensions.Logging.Abstractions" version="8.0.0-rc.1.23419.4" />
<dependency id="Microsoft.Extensions.Configuration" version="8.0.0" />
<dependency id="Microsoft.Extensions.Configuration.Binder" version="8.0.0" />
<dependency id="Microsoft.Extensions.DependencyInjection" version="8.0.0" />
<dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.0" />
<dependency id="Microsoft.Extensions.Hosting.Abstractions" version="8.0.0" />
<dependency id="Microsoft.Extensions.Logging.Abstractions" version="8.0.0" />
<dependency id="System.ComponentModel.Annotations" version="5.0.0" />
<dependency id="System.Runtime.Loader" version="4.3.0" />
</group>
Expand Down
4 changes: 2 additions & 2 deletions NuGet/Definition/Csla.Windows.Forms.NuSpec
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
</group>
<group targetFramework="net8.0-windows10.0.19041">
<dependency id="Csla" version="[4.6.3-Beta10]" />
<dependency id="Microsoft.Extensions.Hosting" version="8.0.0-rc.1.23419.4" />
<dependency id="Microsoft.Extensions.Hosting.Abstractions" version="8.0.0-rc.1.23419.4" />
<dependency id="Microsoft.Extensions.Hosting" version="8.0.0" />
<dependency id="Microsoft.Extensions.Hosting.Abstractions" version="8.0.0" />
</group>
</dependencies>
</metadata>
Expand Down
2 changes: 1 addition & 1 deletion NuGet/Definition/Csla.Wpf.NuSpec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<group targetFramework="net8.0-windows10.0.19041">
<dependency id="Csla" version="[4.6.3-Beta10]" />
<dependency id="Microsoft.Extensions.Hosting" version="8.0.0-rc.2.23479.6" />
<dependency id="Microsoft.Extensions.Hosting.Abstractions" version="8.0.0-rc.2.23479.6" />
<dependency id="Microsoft.Extensions.Hosting.Abstractions" version="8.0.0" />
</group>
</dependencies>
</metadata>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
<TargetFrameworks>net48</TargetFrameworks>
<IsPackable>false</IsPackable>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
Expand All @@ -14,11 +14,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
Expand Down
2 changes: 1 addition & 1 deletion Source/Csla.Analyzers/Csla.Analyzers/Csla.Analyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.1" PrivateAssets="all" />
<PackageReference Update="NETStandard.Library" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
Expand Down
75 changes: 53 additions & 22 deletions Source/Csla.AspNetCore/Blazor/ApplicationContextManagerBlazor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//-----------------------------------------------------------------------
using Csla.Core;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Http;
using System;
using System.Security.Claims;
using System.Security.Principal;
Expand All @@ -16,8 +17,9 @@
namespace Csla.AspNetCore.Blazor
{
/// <summary>
/// Application context manager that uses HttpContextAccessor when
/// resolving HttpContext to store context values.
/// Application context manager that adapts how to manage
/// per-user state and identity for server-rendered and
/// server-interactive Blazor modes.
/// </summary>
public class ApplicationContextManagerBlazor : IContextManager, IDisposable
{
Expand All @@ -42,14 +44,21 @@ public class ApplicationContextManagerBlazor : IContextManager, IDisposable
/// </summary>
protected ActiveCircuitState ActiveCircuitState { get; private set; }

/// <summary>
/// Gets or sets a reference to the current HttpContext.
/// </summary>
protected HttpContext HttpContext { get; set; }

/// <summary>
/// Creates an instance of the object, initializing it
/// with the required IServiceProvider.
/// </summary>
/// <param name="hca">IHttpContextAccessor service</param>
/// <param name="authenticationStateProvider">AuthenticationStateProvider service</param>
/// <param name="activeCircuitState"></param>
public ApplicationContextManagerBlazor(AuthenticationStateProvider authenticationStateProvider, ActiveCircuitState activeCircuitState)
public ApplicationContextManagerBlazor(IHttpContextAccessor hca, AuthenticationStateProvider authenticationStateProvider, ActiveCircuitState activeCircuitState)
{
HttpContext = hca.HttpContext;
AuthenticationStateProvider = authenticationStateProvider;
ActiveCircuitState = activeCircuitState;
CurrentPrincipal = UnauthenticatedPrincipal;
Expand All @@ -59,26 +68,37 @@ public ApplicationContextManagerBlazor(AuthenticationStateProvider authenticatio

private void InitializeUser()
{
Task<AuthenticationState> task = default;
try
{
task = AuthenticationStateProvider.GetAuthenticationStateAsync();
}
catch (InvalidOperationException ex)
if (ActiveCircuitState.CircuitExists)
{
task = Task.FromResult(new AuthenticationState((ClaimsPrincipal)UnauthenticatedPrincipal));
string message = ex.Message;
if (message.Contains(nameof(AuthenticationStateProvider.GetAuthenticationStateAsync))
&& message.Contains(nameof(IHostEnvironmentAuthenticationStateProvider.SetAuthenticationState)))
Task<AuthenticationState> task;
try
{
SetHostPrincipal(task);
task = AuthenticationStateProvider.GetAuthenticationStateAsync();
}
else
catch (InvalidOperationException ex)
{
throw;
task = Task.FromResult(new AuthenticationState((ClaimsPrincipal)UnauthenticatedPrincipal));
string message = ex.Message;
if (message.Contains(nameof(AuthenticationStateProvider.GetAuthenticationStateAsync))
&& message.Contains(nameof(IHostEnvironmentAuthenticationStateProvider.SetAuthenticationState)))
{
SetHostPrincipal(task);
}
else
{
throw;
}
}
AuthenticationStateProvider_AuthenticationStateChanged(task);
}
else if (HttpContext is not null)
{
CurrentPrincipal = HttpContext.User;
}
else
{
throw new InvalidOperationException("HttpContext==null, !CircuitExists");
}
AuthenticationStateProvider_AuthenticationStateChanged(task);
}

private void AuthenticationStateProvider_AuthenticationStateChanged(Task<AuthenticationState> task)
Expand Down Expand Up @@ -106,7 +126,7 @@ private void AuthenticationStateProvider_AuthenticationStateChanged(Task<Authent
/// </summary>
public bool IsValid
{
get { return ActiveCircuitState.CircuitExists; }
get { return HttpContext is not null || ActiveCircuitState.CircuitExists; }
}

/// <summary>
Expand All @@ -132,15 +152,26 @@ public virtual void SetUser(IPrincipal principal)
{
if (!ReferenceEquals(CurrentPrincipal, principal))
{
if (principal is ClaimsPrincipal claimsPrincipal)
if (ActiveCircuitState.CircuitExists)
{
if (principal is ClaimsPrincipal claimsPrincipal)
{
SetHostPrincipal(Task.FromResult(new AuthenticationState(claimsPrincipal)));
}
else
{
throw new ArgumentException("typeof(principal) != ClaimsPrincipal");
}
}
else if (HttpContext is not null)
{
CurrentPrincipal = principal;
SetHostPrincipal(Task.FromResult(new AuthenticationState(claimsPrincipal)));
HttpContext.User = (ClaimsPrincipal)principal;
}
else
{
throw new ArgumentException("typeof(principal) != ClaimsPrincipal");
throw new InvalidOperationException("HttpContext==null, !CircuitExists");
}
CurrentPrincipal = principal;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Csla.AspNetCore/Csla.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.0-rc.2.23480.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
Expand Down
56 changes: 0 additions & 56 deletions Source/Csla.Blazor.Test/ApplicationContextTests.cs

This file was deleted.

8 changes: 4 additions & 4 deletions Source/Csla.Blazor.Test/Csla.Blazor.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<ApplicationIcon />
<OutputType>Library</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
Expand Down
4 changes: 2 additions & 2 deletions Source/Csla.Blazor.WebAssembly/Csla.Blazor.WebAssembly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0-rc.2.23480.2" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0-rc.1.23419.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
Expand Down
8 changes: 4 additions & 4 deletions Source/Csla.Blazor/Csla.Blazor.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
Expand Down Expand Up @@ -27,9 +27,9 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.0-rc.2.23480.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0-rc.2.23480.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.0-rc.2.23480.2" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Source/Csla.TestHelpers/Csla.TestHelpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ private async Task InvokePortal(string operation, Stream requestStream, Stream r
DataPortalErrorInfo errorData = null;
if (UseTextSerialization)
{
Response.Headers.Add("Content-type", "application/base64,text/plain");
Response.Headers["Content-type"] = "application/base64,text/plain";
}
else
{
Response.Headers.Add("Content-type", "application/octet-stream");
Response.Headers["Content-type"] = "application/octet-stream";
}
SetHttpResponseHeaders(Response);
try
Expand Down
Loading

0 comments on commit 6d159d2

Please sign in to comment.