Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

815
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda