How to store data related to a Blazor Server circuit?

355 views Asked by At

I'm reusing old WinForms client code in a Blazor Server app. The problem is that the WinForms code expects a few static variables with state that are created when the app starts and then used everywhere.

I want to replace those static variables with static properties that store the data in static variables for WinForms and in some kind of datastore tied to the Circuit for Blazor Server.

I've was happily using HttpContext, but it seems it only works in development, not in production. Is there something equivalent to HttContext for Blazor circuits? Maybe a dictionary where to store data? Or at least a static property to get the circuit Id?

Edit for clarification:

For example this static properties are assigned when the user logins

public class UserData
{
   public static int Id { get; set; }
   public static string Name { get; set; }
}

I was hopping to change it to something like:

public static int Id
{ 
    get
    {
        return (int)httpContext.Items["UserId"];
    }
    set
    {
        httpContext.Items["UserId"] = value;
    }
}

These static values are used everywhere in the old code.

0

There are 0 answers