Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

789
Views
Initialize Blazor scoped service using async method before components are initialized

I have a scoped service:

services.AddScoped<UserSettingsService>();

I want to call async method on the service (load data from DB) before child components are initialized (before ComponentBase.OnInitialized();)

Where is the best place to call UserSettingsService.LoadAsync();?

I have tried to do it in App component in OnInitializedAsync(), but it seems too late, because my childcomponents has been initialized before the UserSettingsService:

app.razor.cs:

public partial class App {
  [Inject] UserSettingsService UserSettingsService {get; set;}
  [Inject] AuthenticationStateService AuthenticationStateService {get; set;}
 
  public override async Task OnInitializedAsync() {
     string userName = (await AuthenticationStateService.GetAuthenticationState()).User.Identity.Name;
     await UserSettingsService.LoadAsync(userName );
     await base.OnInitializedAsync();
  }
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

As far as I know, SetparametersAsync should do the trick.

The image is very clear about the blazor component lifecycle: https://knowledgebasehavit.files.wordpress.com/2019/11/blazor-component-lifecycle-diagram.png

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!