This isn't specific to Blazor, but in any class you can create code in the constructor of your component/
Here I have a Chat component, that I break up into
Chat.razor
Chat.razor.cs
The chat.razor.cs you create by adding a class with the same name as your component, then add the word partial to make it a partial class:
partial class Chat : IBlazorComponent, IBlazorComponentParent, IDisposable
Note: The interfaces are just for my app, I am just showing the line with partial.
really are you need it:
partial class Chat
Then in my constructor I created:
public Chat()
{
// Perform initializations for this object
Init();
}
I just call a method, you don't have to:
My Init method:
public void Init()
{
// do your initializations
}
Or you can use OnInitializedAsync
protected override async Task OnInitializedAsync()
{
// load the Categories (example)
this.Categories = await HelpCategoryService.GetHelpCategoryList()
}
Or here is another I use sometimes: OnAfterRender
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
...
}
}
Documentation for that is here:
https://learn.microsoft.com/en-us/aspnet/core/blazor/lifecycle?view=aspnetcore-3.1
Maybe that gives you some ideas. Not sure about Standard, every use case is different.
Note: I have never used Blazor Web Assembly, only server side Blazor, so not sure what is specific to WASM, but I know constructors work in any C# class.