© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
4 replies
Camster

❔ Blazor State Container Prompt, Standardized for all Pages

I have a simple state container in blazor. The goal is to provide the AppEntity value:

public class StateContainer {
    public AppEntity App { get; set; }
    public event Action OnStateChange;
    public void SetApp(AppEntity app) {
        App = app;
        NotifyStateChanged();
    }

    private void NotifyStateChanged() => OnStateChange?.Invoke();
}
public class StateContainer {
    public AppEntity App { get; set; }
    public event Action OnStateChange;
    public void SetApp(AppEntity app) {
        App = app;
        NotifyStateChanged();
    }

    private void NotifyStateChanged() => OnStateChange?.Invoke();
}


The container is injected in the services collection.

builder.Services.AddSingleton<StateContainer>();
builder.Services.AddSingleton<StateContainer>();


I have a component which provides the user a selection dropdown to set the AppEntity in the State Container. Subsequent pages inject the State Container and use it if needed.

My question is: if for some reason a page that requires the State Container has a null value for AppEntity (e.g., user navigated to a specific page by url, bypassing the selection page), how can I have a generic popup prompt that prompts the user for the selection? Ideally, I'd want to minimize the code in any page that needs it as much as possible. The only way I can think to do this is to build the prompt in a base component and inherit from it, but perhaps there might be a simpler or more elegant way.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Blazor reactive state
C#CC# / help
2y ago
✅ Blazor vs Razor Pages
C#CC# / help
3y ago
✅ Blazor or Razor pages
C#CC# / help
3y ago
Blazor cross component state mutation
C#CC# / help
12mo ago