Cortex.Net icon indicating copy to clipboard operation
Cortex.Net copied to clipboard

Having shared models across multiple blazor server pages.

Open pauldotknopf opened this issue 4 years ago • 1 comments

I need to have some state shared across all users/sessions.

I've registered my model:

services.AddSingleton<CustomState>(context =>
{
    return context.GetRequiredService<ISharedState>().Observable(() => new CustomState());
});

This is in my blazor page:

@inject CustomState _customState
@attribute [Observer]

<button class="btn btn-primary" @onclick="TestFunction">Click me</button>
<p>Shared state: @_customState.Title</p>

[Cortex.Net.Api.Action]
private void TestFunction()
{
    _customState.Title = Guid.NewGuid().ToString();
}

If I open a single page, the UI updates with the new Guid.

If I open another page, the initial render shows the right Guid. However, if I click the button, I would expect (hope) that both pages get re-rendered.

Is this a supported use-case? How would I achieve this effect?

pauldotknopf avatar May 20 '21 13:05 pauldotknopf

Have you figured this out? When I try to share models across several users in Blazor server, I end up getting: image

wihrl avatar May 03 '22 18:05 wihrl