Skip to content

Commit a2f861e

Browse files
Fix issue with context manager in a Blazor server setting (#4183)
* 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
1 parent 1ff5352 commit a2f861e

File tree

13 files changed

+103
-27
lines changed

13 files changed

+103
-27
lines changed

Samples/ProjectTracker/ProjectTracker.AppServer/ProjectTracker.AppServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Csla.AspNetCore" Version="8.0.0-R24032502" />
10+
<PackageReference Include="Csla.AspNetCore" Version="8.2.6" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

Samples/ProjectTracker/ProjectTracker.Blazor/ProjectTracker.Blazor.Client/ProjectTracker.Blazor.Client.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
<ItemGroup>
1212
<ProjectReference Include="..\..\ProjectTracker.BusinessLibrary\ProjectTracker.BusinessLibrary.csproj" />
13-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.2" />
14-
<PackageReference Include="Csla.Blazor" Version="8.0.0-R24032502" />
15-
<PackageReference Include="Csla.Blazor.WebAssembly" Version="8.0.0-R24032502" />
13+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.8" />
14+
<PackageReference Include="Csla.Blazor" Version="8.2.6" />
15+
<PackageReference Include="Csla.Blazor.WebAssembly" Version="8.2.6" />
1616
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
1717
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
1818
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />

Samples/ProjectTracker/ProjectTracker.Blazor/ProjectTracker.Blazor/ProjectTracker.Blazor.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
@@ -12,9 +12,9 @@
1212
<ProjectReference Include="..\..\ProjectTracker.DalMock\ProjectTracker.DalMock.csproj" />
1313
<ProjectReference Include="..\..\ProjectTracker.Dal\ProjectTracker.Dal.csproj" />
1414
<ProjectReference Include="..\ProjectTracker.Blazor.Client\ProjectTracker.Blazor.Client.csproj" />
15-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.2" />
16-
<PackageReference Include="Csla.AspNetCore" Version="8.0.0-R24032502" />
17-
<PackageReference Include="Csla.Blazor" Version="8.0.0-R24032502" />
15+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.8" />
16+
<PackageReference Include="Csla.AspNetCore" Version="8.2.6" />
17+
<PackageReference Include="Csla.Blazor" Version="8.2.6" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

Samples/ProjectTracker/ProjectTracker.BusinessLibrary/ProjectTracker.BusinessLibrary.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Csla" Version="8.0.0-R24032502" />
11-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
10+
<PackageReference Include="Csla" Version="8.2.6" />
11+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

Samples/ProjectTracker/ProjectTracker.Dal/ProjectTracker.Dal.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Csla" Version="8.0.0-R24032502" />
11-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
10+
<PackageReference Include="Csla" Version="8.2.6" />
11+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
1212
</ItemGroup>
1313

1414
</Project>

Samples/ProjectTracker/ProjectTracker.DalEfCore/ProjectTracker.DalEfCore.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
9-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
10-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
8+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
10+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

Samples/ProjectTracker/ProjectTracker.DalMock/ProjectTracker.DalMock.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Csla" Version="8.0.0-R24032502" />
11-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
10+
<PackageReference Include="Csla" Version="8.2.6" />
11+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

Samples/ProjectTracker/global.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.401"
4+
}
5+
}

Source/Csla.Blazor.Test/AppContext/ContextManagerTests.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
// <summary>Context Manager configuration tests</summary>
77
//-----------------------------------------------------------------------
88

9+
using System.Security.Claims;
910
using Csla.Configuration;
1011
using Microsoft.AspNetCore.Components.Authorization;
12+
using Microsoft.AspNetCore.Http;
13+
using Microsoft.AspNetCore.Http.Features;
1114
using Microsoft.Extensions.DependencyInjection;
1215
using Microsoft.VisualStudio.TestTools.UnitTesting;
1316

@@ -53,7 +56,42 @@ public void UseApplicationContextManagerBlazor()
5356

5457
var applicationContext = serviceProvider.GetRequiredService<ApplicationContext>();
5558
Assert.IsInstanceOfType(applicationContext.ContextManager, typeof(Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor));
59+
}
60+
61+
[TestMethod]
62+
public void UseAsyncLocalApplicationContextManager()
63+
{
64+
var services = new ServiceCollection();
65+
services.AddScoped<AuthenticationStateProvider, AuthenticationStateProviderFake>();
66+
services.AddHttpContextAccessor();
67+
services.AddCsla(o => o
68+
.AddAspNetCore()
69+
.AddServerSideBlazor(o => o.UseInMemoryApplicationContextManager = false));
70+
var serviceProvider = services.BuildServiceProvider();
71+
72+
var activeState = serviceProvider.GetRequiredService<AspNetCore.Blazor.ActiveCircuitState>();
73+
activeState.CircuitExists = false;
74+
75+
var applicationContext = serviceProvider.GetRequiredService<ApplicationContext>();
76+
Assert.IsInstanceOfType(applicationContext.ContextManager, typeof(Csla.Core.ApplicationContextManagerAsyncLocal));
77+
}
78+
79+
[TestMethod]
80+
public void UseAspNetCoreApplicationContextManager()
81+
{
82+
var services = new ServiceCollection();
83+
services.AddScoped<AuthenticationStateProvider, AuthenticationStateProviderFake>();
84+
services.AddScoped<IHttpContextAccessor, HttpContextAccessorFake>();
85+
services.AddCsla(o => o
86+
.AddAspNetCore()
87+
.AddServerSideBlazor(o => o.UseInMemoryApplicationContextManager = false));
88+
var serviceProvider = services.BuildServiceProvider();
5689

90+
var activeState = serviceProvider.GetRequiredService<AspNetCore.Blazor.ActiveCircuitState>();
91+
activeState.CircuitExists = false;
92+
93+
var applicationContext = serviceProvider.GetRequiredService<ApplicationContext>();
94+
Assert.IsInstanceOfType(applicationContext.ContextManager, typeof(Csla.AspNetCore.ApplicationContextManagerHttpContext));
5795
}
5896
}
5997

@@ -65,3 +103,30 @@ public override Task<AuthenticationState> GetAuthenticationStateAsync()
65103
throw new System.NotImplementedException();
66104
}
67105
}
106+
107+
public class HttpContextAccessorFake : IHttpContextAccessor
108+
{
109+
public HttpContext HttpContext { get; set; } = new HttpContextFake();
110+
}
111+
112+
public class HttpContextFake : HttpContext
113+
{
114+
public override IFeatureCollection Features => throw new NotImplementedException();
115+
116+
public override HttpRequest Request => throw new NotImplementedException();
117+
118+
public override HttpResponse Response => throw new NotImplementedException();
119+
120+
public override ConnectionInfo Connection => throw new NotImplementedException();
121+
122+
public override WebSocketManager WebSockets => throw new NotImplementedException();
123+
124+
public override ClaimsPrincipal User { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
125+
public override IDictionary<object, object> Items { get; set; } = new Dictionary<object, object>();
126+
public override IServiceProvider RequestServices { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
127+
public override CancellationToken RequestAborted { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
128+
public override string TraceIdentifier { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
129+
public override ISession Session { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
130+
131+
public override void Abort() => throw new NotImplementedException();
132+
}

Source/Csla.Blazor/ConfigurationExtensions.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,7 @@ public static CslaOptions AddServerSideBlazor(this CslaOptions config, Action<Bl
4848
managerTypeName = "Csla.AspNetCore.Blazor.ApplicationContextManagerInMemory,Csla.AspNetCore";
4949
else
5050
managerTypeName = "Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor,Csla.AspNetCore";
51-
var managerType = Type.GetType(managerTypeName);
52-
if (managerType is null)
53-
throw new TypeLoadException(managerTypeName);
54-
var contextManagerType = typeof(Core.IContextManager);
55-
var managers = config.Services.Where(i => i.ServiceType.Equals(contextManagerType)).ToList();
56-
foreach ( var manager in managers )
57-
config.Services.Remove(manager);
51+
var managerType = Type.GetType(managerTypeName) ?? throw new TypeLoadException(managerTypeName);
5852
config.Services.AddScoped(typeof(IContextManager), managerType);
5953

6054
if (blazorOptions.UseInMemoryApplicationContextManager)

Source/Csla.Xaml.Uwp/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
// You can specify all the values or you can default the Build and Revision Numbers
2828
// by using the '*' as shown below:
2929
// [assembly: AssemblyVersion("1.0.*")]
30-
[assembly: AssemblyVersion("8.2.5.0")]
31-
[assembly: AssemblyFileVersion("8.2.5.0")]
30+
[assembly: AssemblyVersion("8.2.6.0")]
31+
[assembly: AssemblyFileVersion("8.2.6.0")]

Source/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<!-- Common Package Settings -->
88
<PropertyGroup>
9-
<Version>8.2.5.0</Version>
9+
<Version>8.2.6.0</Version>
1010
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1111
<PackageProjectUrl>https://cslanet.com</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/MarimerLLC/csla</RepositoryUrl>

releasenotes.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

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

5+
## CSLA .NET version 8.2.6 release
6+
7+
Fixes issues with the way `IContextManager` is resolved in Blazor apps in #4089 and #4182.
8+
9+
### Change List
10+
11+
* https://github.com/MarimerLLC/csla/compare/v8.2.5...v8.2.6
12+
13+
### Contributors
14+
15+
* @rockfordlhotka
16+
517
## CSLA .NET version 8.2.5 release
618

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

0 commit comments

Comments
 (0)