MarimerLLC / csla

A home for your business logic in any .NET application.
https://cslanet.com
MIT License
1.25k stars 400 forks source link

Fix Blazor context manager service config issue #4089

Closed rockfordlhotka closed 1 month ago

rockfordlhotka commented 1 month ago

I am working with Scoped Services that retrieve information using CSLA Business Objects. After upgrading to version 8.2.5, I encountered the following error:

Do not call GetAuthenticationStateAsync outside of the DI scope for a Razor component

I noticed that this issue might have been addressed in #3614 , but it still persists for me with the following configuration:

builder.Services.AddCsla(o => o
             .AddAspNetCore()
             .AddServerSideBlazor(ssb => ssb.UseInMemoryApplicationContextManager = true)
             .Security(so => so.FlowSecurityPrincipalFromClient = true)
             .DataPortal(dpo => dpo
               .AddServerSideDataPortal()
               .ClientSideDataPortal(co => co
                   .UseLocalProxy())));

Can someone provide guidance on the proper configuration needed to call a CSLA Business Object from a Service within a Razor component?

Originally posted by @jmpotvin in https://github.com/MarimerLLC/csla/discussions/4088

rockfordlhotka commented 1 month ago

@jmpotvin

I started creating some unit tests with a config like this, and it works:

builder.Services.AddCsla(o => o
             .AddAspNetCore()
             .AddServerSideBlazor(ssb => ssb.UseInMemoryApplicationContextManager = true)
             .Security(so => so.FlowSecurityPrincipalFromClient = true));

This is all you should normally need to set up a Blazor server app.

I'll test with the extra data portal config later, but that shouldn't be necessary at all.

jmpotvin commented 1 month ago

Thanks @rockfordlhotka.

I converted everything to 8.2.5, and it's working fine now. I'm not sure what I was doing wrong before.