csla: .NET 8.0: Do not call GetAuthenticationStateAsync outside of the DI scope for a Razor component
Out of interest, I switched a project over to .NET 8.0 and updated all NuGet packages, but still using CSLA 7.0.2. Nothing that requires an IDataPortal<T> seems to work anymore in Blazor. I checked CSLA Version 8.0.0 but it wasn’t obvious if this was being tracked.
Do not call GetAuthenticationStateAsync outside of the DI scope for a Razor component. Typically, this means you can call it only within a Razor component or inside another DI service that is resolved for a Razor component.
The following is inside a razor component, using the appropriate Task<AuthenticationState>:
[CascadingParameter] protected Task<AuthenticationState> AuthenticationStateTask { get; set; }
protected async override Task OnInitializedAsync()
{
var authState = await AuthenticationStateTask;
...
var result = await WidgetListFactory.GetAsync(); // This uses IDataPortal<WidgetList> and throws
_ = base.OnInitializedAsync();
}
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Comments: 15 (7 by maintainers)
Commits related to this issue
- #3583 Update BlazorExample to build and partially run on .NET 8 — committed to rockfordlhotka/csla by rockfordlhotka 7 months ago
- #3583 Blazor context manager now works with server-rendered and server-interactive modes — committed to rockfordlhotka/csla by rockfordlhotka 6 months ago
- #3583 Blazor context manager now works with server-rendered and server-interactive modes — committed to russblair/csla by rockfordlhotka 6 months ago
I now have a #dotnet #blazor app that is able to maintain per-user state across server-rendered, server-interactive, and wasm-interactive pages in a single app. It still needs some refinement, but at least the concept is proven to work!
Blog post is the next thing on the agenda.
https://github.com/rockfordlhotka/Blazor8State
I’ve had a bit of a breakthrough with the Blazor8State project, where (as long as the server rendered pages use streaming) state is able to flow from page to page, including from wasm interactive back to server rendered pages.
All of this, btw, is necessary for
LocalContextandClientContextto work as expected in CSLA.Rocky,
I’m in Germany, Frankfurt. If you need a place to crash, give me a call.
Have a nice day.
Kevin
https://rb.gy/syiuf
From: Rockford Lhotka @.> Sent: Tuesday, November 21, 2023 8:07 AM To: MarimerLLC/csla @.> Cc: Kevin Cabral @.>; Comment @.> Subject: Re: [MarimerLLC/csla] .NET 8.0: Do not call GetAuthenticationStateAsync outside of the DI scope for a Razor component (Issue #3583)
There’s a built-in way to pass authentication state through a new Blazor 8 cascading type.
I’m at lunch in Prague, so don’t have my computer to look it up.
— Reply to this email directly, view it on GitHubhttps://github.com/MarimerLLC/csla/issues/3583#issuecomment-1820893667, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGJTVDWPDAKOFKQQMTQPXYLYFSRS3AVCNFSM6AAAAAA7T77SCGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRQHA4TGNRWG4. You are receiving this because you commented.Message ID: @.***>