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

816
Views
Inicialice el servicio con ámbito de Blazor mediante el método asíncrono antes de que se inicialicen los componentes

Tengo un servicio de alcance:

 services.AddScoped<UserSettingsService>();

Quiero llamar al método asíncrono en el servicio (cargar datos de la base de datos) antes de que se inicialicen los componentes secundarios (antes ComponentBase.OnInitialized(); )

¿Cuál es el mejor lugar para llamar a UserSettingsService.LoadAsync(); ?

Intenté hacerlo en el componente de la aplicación en OnInitializedAsync(), pero parece demasiado tarde, porque mis componentes secundarios se inicializaron antes que UserSettingsService:

aplicación.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

Hasta donde yo sé, SetparametersAsync debería funcionar.

La imagen es muy clara sobre el ciclo de vida del componente blazor: 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!