Skip to content

Commit

Permalink
Fix issue with context manager in a Blazor server setting (#4183)
Browse files Browse the repository at this point in the history
* Update to latest nuget packages

* Ensure use of .NET 8 b/c .NET 9 has a bug

* Update version numbers to 8.2.6

* Add context manager tests

* Make HttpContext fake function enough for testing

* #4182 Don't remove other context managers, b/c the accessor needs to scan them all

* Target latest .NET 8 SDK

* Update to target CSLA 8.2.6

* Update release notes
  • Loading branch information
rockfordlhotka authored Aug 23, 2024
1 parent 1ff5352 commit a2f861e
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Csla.AspNetCore" Version="8.0.0-R24032502" />
<PackageReference Include="Csla.AspNetCore" Version="8.2.6" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

<ItemGroup>
<ProjectReference Include="..\..\ProjectTracker.BusinessLibrary\ProjectTracker.BusinessLibrary.csproj" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.2" />
<PackageReference Include="Csla.Blazor" Version="8.0.0-R24032502" />
<PackageReference Include="Csla.Blazor.WebAssembly" Version="8.0.0-R24032502" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.8" />
<PackageReference Include="Csla.Blazor" Version="8.2.6" />
<PackageReference Include="Csla.Blazor.WebAssembly" Version="8.2.6" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -12,9 +12,9 @@
<ProjectReference Include="..\..\ProjectTracker.DalMock\ProjectTracker.DalMock.csproj" />
<ProjectReference Include="..\..\ProjectTracker.Dal\ProjectTracker.Dal.csproj" />
<ProjectReference Include="..\ProjectTracker.Blazor.Client\ProjectTracker.Blazor.Client.csproj" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.2" />
<PackageReference Include="Csla.AspNetCore" Version="8.0.0-R24032502" />
<PackageReference Include="Csla.Blazor" Version="8.0.0-R24032502" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.8" />
<PackageReference Include="Csla.AspNetCore" Version="8.2.6" />
<PackageReference Include="Csla.Blazor" Version="8.2.6" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Csla" Version="8.0.0-R24032502" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Csla" Version="8.2.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Csla" Version="8.0.0-R24032502" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Csla" Version="8.2.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Csla" Version="8.0.0-R24032502" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Csla" Version="8.2.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions Samples/ProjectTracker/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "8.0.401"
}
}
65 changes: 65 additions & 0 deletions Source/Csla.Blazor.Test/AppContext/ContextManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
// <summary>Context Manager configuration tests</summary>
//-----------------------------------------------------------------------

using System.Security.Claims;
using Csla.Configuration;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -53,7 +56,42 @@ public void UseApplicationContextManagerBlazor()

var applicationContext = serviceProvider.GetRequiredService<ApplicationContext>();
Assert.IsInstanceOfType(applicationContext.ContextManager, typeof(Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor));
}

[TestMethod]
public void UseAsyncLocalApplicationContextManager()
{
var services = new ServiceCollection();
services.AddScoped<AuthenticationStateProvider, AuthenticationStateProviderFake>();
services.AddHttpContextAccessor();
services.AddCsla(o => o
.AddAspNetCore()
.AddServerSideBlazor(o => o.UseInMemoryApplicationContextManager = false));
var serviceProvider = services.BuildServiceProvider();

var activeState = serviceProvider.GetRequiredService<AspNetCore.Blazor.ActiveCircuitState>();
activeState.CircuitExists = false;

var applicationContext = serviceProvider.GetRequiredService<ApplicationContext>();
Assert.IsInstanceOfType(applicationContext.ContextManager, typeof(Csla.Core.ApplicationContextManagerAsyncLocal));
}

[TestMethod]
public void UseAspNetCoreApplicationContextManager()
{
var services = new ServiceCollection();
services.AddScoped<AuthenticationStateProvider, AuthenticationStateProviderFake>();
services.AddScoped<IHttpContextAccessor, HttpContextAccessorFake>();
services.AddCsla(o => o
.AddAspNetCore()
.AddServerSideBlazor(o => o.UseInMemoryApplicationContextManager = false));
var serviceProvider = services.BuildServiceProvider();

var activeState = serviceProvider.GetRequiredService<AspNetCore.Blazor.ActiveCircuitState>();
activeState.CircuitExists = false;

var applicationContext = serviceProvider.GetRequiredService<ApplicationContext>();
Assert.IsInstanceOfType(applicationContext.ContextManager, typeof(Csla.AspNetCore.ApplicationContextManagerHttpContext));
}
}

Expand All @@ -65,3 +103,30 @@ public override Task<AuthenticationState> GetAuthenticationStateAsync()
throw new System.NotImplementedException();
}
}

public class HttpContextAccessorFake : IHttpContextAccessor
{
public HttpContext HttpContext { get; set; } = new HttpContextFake();
}

public class HttpContextFake : HttpContext
{
public override IFeatureCollection Features => throw new NotImplementedException();

public override HttpRequest Request => throw new NotImplementedException();

public override HttpResponse Response => throw new NotImplementedException();

public override ConnectionInfo Connection => throw new NotImplementedException();

public override WebSocketManager WebSockets => throw new NotImplementedException();

public override ClaimsPrincipal User { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override IDictionary<object, object> Items { get; set; } = new Dictionary<object, object>();
public override IServiceProvider RequestServices { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override CancellationToken RequestAborted { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override string TraceIdentifier { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override ISession Session { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

public override void Abort() => throw new NotImplementedException();
}
8 changes: 1 addition & 7 deletions Source/Csla.Blazor/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ public static CslaOptions AddServerSideBlazor(this CslaOptions config, Action<Bl
managerTypeName = "Csla.AspNetCore.Blazor.ApplicationContextManagerInMemory,Csla.AspNetCore";
else
managerTypeName = "Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor,Csla.AspNetCore";
var managerType = Type.GetType(managerTypeName);
if (managerType is null)
throw new TypeLoadException(managerTypeName);
var contextManagerType = typeof(Core.IContextManager);
var managers = config.Services.Where(i => i.ServiceType.Equals(contextManagerType)).ToList();
foreach ( var manager in managers )
config.Services.Remove(manager);
var managerType = Type.GetType(managerTypeName) ?? throw new TypeLoadException(managerTypeName);
config.Services.AddScoped(typeof(IContextManager), managerType);

if (blazorOptions.UseInMemoryApplicationContextManager)
Expand Down
4 changes: 2 additions & 2 deletions Source/Csla.Xaml.Uwp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("8.2.5.0")]
[assembly: AssemblyFileVersion("8.2.5.0")]
[assembly: AssemblyVersion("8.2.6.0")]
[assembly: AssemblyFileVersion("8.2.6.0")]
2 changes: 1 addition & 1 deletion Source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!-- Common Package Settings -->
<PropertyGroup>
<Version>8.2.5.0</Version>
<Version>8.2.6.0</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://cslanet.com</PackageProjectUrl>
<RepositoryUrl>https://github.com/MarimerLLC/csla</RepositoryUrl>
Expand Down
12 changes: 12 additions & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

CSLA 8 is a substantial update to CSLA .NET, adding support for .NET 8 and other enhancements.

## CSLA .NET version 8.2.6 release

Fixes issues with the way `IContextManager` is resolved in Blazor apps in #4089 and #4182.

### Change List

* https://github.com/MarimerLLC/csla/compare/v8.2.5...v8.2.6

### Contributors

* @rockfordlhotka

## CSLA .NET version 8.2.5 release

* [#4075](https://github.com/MarimerLLC/csla/issues/4075) Fix configuration issue with Blazor DI services
Expand Down

0 comments on commit a2f861e

Please sign in to comment.