User-1629310966 posted
I want to store data in an object and I want to use this in the whole app. I created an Object and register as Singleton in Program.cs
Object:
private Dictionary<string, string> _currentValues;
public Dictionary<string, string> currentValues
{
get => _currentValues;
set
{
_currentValues = value;
StateHasChanged();
}
}
Singleton Registration:
services.AddSingleton<LocalizeData>();
In program.cs after registration I added initial data.
var _localizeData = host.Services.GetRequiredService<LocalizeData>();
_localizeData.currentValues = locaData;
Now I want to use these data in the whole app. I injected it in each page in which I want to use the data
@LocalizeData localizeData
If I use now localizeData.currentValues
the object is null.
What is missing. How can I initialize an object in Starttup
and how can I use the data in whole app?