Skip to content

Having shared models across multiple blazor server pages. #57

@pauldotknopf

Description

@pauldotknopf

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions