I have a Blazor server side app. All the user specific variables I have defined in a scoped service. (TagService). With my app the user can connect to a production machine and read their PLC and CNC data. If the user disconnects from the current machine, I want that all the variables that are defined in the scoped service are initialized to their defined default values (Like 0 or "") I do that normally in a classic way shown in the code below.
When the user clicks the disconnect button I call a function in the scoped service where I set all the user specific variables to their default values one by one. I have few hundred variables and I loose more and more the overview in this way.
Is there an easier way, so that I can reinitialize all the variables in a scoped service to their initial values with just one command instead of setting back their values one by one to their default values?
Razor page code
@inject TagService TagService
<button @onclick="Disconnect">Disconnect</button>
private void Disconnect()
{
TagService.Delete_UserTags();
}
Scoped Service (TagService)
public class TagService
{
public int Tag1=0;
public int Tag2=0;
public int Tag3=1;
public string Tag4="";
// few hundred Tags
public void Delete_UserTags()
{
Tag1=0;
Tag2=0;
Tag3=0;
Tag4="";
//setting all the few hundred tags to their initial value
}
}