Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having shared models across multiple blazor server pages. #57

Open
pauldotknopf opened this issue May 20, 2021 · 1 comment
Open

Having shared models across multiple blazor server pages. #57

pauldotknopf opened this issue May 20, 2021 · 1 comment

Comments

@pauldotknopf
Copy link

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?

@wihrl
Copy link

wihrl commented May 3, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants