I am writing a Blazor Server application that needs to persist data for the user.
I have tried the following / the following does not meet the requirements:
Some ideas I had but are unsure how to implement / if they are good ideas:
Other than that I don't have any other good ideas on how to implement this so any ideas / suggestions are welcomed.
Well, this is not original to me, but here's how I persist Tenant for the logged in user for as long as they are connected.
public class GlobalService
{
public event Action<PropertyChangedEventArgs> PropertyChanged;
Subscriber _Tenant;
public Subscriber Tenant
{
get
{
return _Tenant;
}
set
{
if (!object.Equals(_Tenant, value))
{
var args = new PropertyChangedEventArgs() { Name = "Tenant", NewValue = value, OldValue = _Tenant, IsGlobal = true };
_Tenant = value;
PropertyChanged?.Invoke(args);
}
}
}
}
public class PropertyChangedEventArgs
{
public string Name { get; set; }
public object NewValue { get; set; }
public object OldValue { get; set; }
public bool IsGlobal { get; set; }
}
And I register it in ConfigureServices like so
services.TryAddScoped<GlobalService>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With