From 5ebd9f943fb4ade9884b1b4c2bb6a4920dd27a7d Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Tue, 1 Oct 2024 17:47:15 -0500 Subject: [PATCH] #4182 Fix issue with Blazor context manager --- .../Blazor/ApplicationContextManagerBlazor.cs | 2 +- .../AppContext/ContextManagerTests.cs | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Source/Csla.AspNetCore/Blazor/ApplicationContextManagerBlazor.cs b/Source/Csla.AspNetCore/Blazor/ApplicationContextManagerBlazor.cs index 5f5bcf0d4a..738daa90ba 100644 --- a/Source/Csla.AspNetCore/Blazor/ApplicationContextManagerBlazor.cs +++ b/Source/Csla.AspNetCore/Blazor/ApplicationContextManagerBlazor.cs @@ -112,7 +112,7 @@ private void AuthenticationStateProvider_AuthenticationStateChanged(Task public bool IsValid { - get { return HttpContext is not null || ActiveCircuitState.CircuitExists; } + get { return ActiveCircuitState.CircuitExists; } } /// diff --git a/Source/Csla.Blazor.Test/AppContext/ContextManagerTests.cs b/Source/Csla.Blazor.Test/AppContext/ContextManagerTests.cs index 6974115f7d..9dff46a42b 100644 --- a/Source/Csla.Blazor.Test/AppContext/ContextManagerTests.cs +++ b/Source/Csla.Blazor.Test/AppContext/ContextManagerTests.cs @@ -88,12 +88,30 @@ public void UseBlazorApplicationContextManager() var serviceProvider = services.BuildServiceProvider(); var activeState = serviceProvider.GetRequiredService(); - activeState.CircuitExists = false; + activeState.CircuitExists = true; var applicationContext = serviceProvider.GetRequiredService(); Assert.IsInstanceOfType(applicationContext.ContextManager, typeof(Csla.AspNetCore.Blazor.ApplicationContextManagerBlazor)); } + [TestMethod] + public void UseAspNetCoreOverBlazorApplicationContextManager() + { + var services = new ServiceCollection(); + services.AddScoped(); + services.AddScoped(); + services.AddCsla(o => o + .AddAspNetCore() + .AddServerSideBlazor(o => o.UseInMemoryApplicationContextManager = false)); + var serviceProvider = services.BuildServiceProvider(); + + var activeState = serviceProvider.GetRequiredService(); + activeState.CircuitExists = false; + + var applicationContext = serviceProvider.GetRequiredService(); + Assert.IsInstanceOfType(applicationContext.ContextManager, typeof(Csla.AspNetCore.ApplicationContextManagerHttpContext)); + } + [TestMethod] public void UseAspNetCoreApplicationContextManager() {