I have this in Program.cs. My intent is that when userSession.OnIdentityChangedAsync has been fired (the user is allowed to impersonate an identity) the cascading value of ActingIdentity is then refreshed throughout the app.
builder.Services.AddCascadingValue(
sp =>
{
var userSession= sp.GetRequiredService<IUserSession<TPrincipal>>();
var source = new CascadingValueSource<ActingIdentity<TPrincipal>>(
"ActingIdentity",
()=>userSession.ActingIdentity,
isFixed:false);
var log = sp.GetRequiredService<Microsoft.Extensions.Logging.ILogger>();
userSession.OnIdentityChangedAsync += async () =>
{
await source.NotifyChangedAsync();
log.LogDebug("ActingIdentity Cascading Value Changed to {ActingIdentity}:{@source}",
userSession.ActingIdentity.ActingAs.Identity?.Name??"<null>",
source);
};
return source;
});
But what my logs show me is:
- The event handler you see here is called, so I am confident that source.NotifyChangedAsync() was called
- OnParametersSetAsync() does get called on a page that has a matching CascadingParameter.
- But the parameter value passed is stale. Only the initial value of the parameter is ever seen, subsequent changes are not passed on.
I'm on Net8 with InteractiveServer rendering:
builder.Services
.AddRazorComponents()
.AddInteractiveServerComponents();
If instead of a root cascading value service I instead use <CascadingValue ...>
markup in my Layout page, the changed value is passed to the page as expected.
Why doesn't my attempt at using AddCascadingValue()
work?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743780682a4505741.html
评论列表(0条)