Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

359
Vistas
Should I call IAsyncDisposable.DisposeAsync() in Program.cs using JS module?

I need to configure localization in Blazor WASM, .NET 6

According to the manual, I need to use JavaScript in the Program.cs file. Microsoft recommends connecting JavaScript code through JavaScript isolation in JavaScript modules. However, the code specified in the example is the Blazor component, and IAsyncDisposable.DisposeAsync() is called there

Do I need to call IAsyncDisposable.DisposeAsync() in Program.cs and if so, how to do it without resorting to creating the Program class and the Main method, but using a new version of the console program template?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The question is very stupid on my part. I didn't see the most obvious solution.

You can just call the DisposeAsync() method manually when the object is no longer needed.

As a result, the code will look like this. The code is slightly different from the template, so part of the logic is placed in a separate class.

using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.JSInterop;

using Store.Client;
using Store.Client.Engine;

using System.Globalization;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddLocalization();

var host = builder.Build();

var js = host.Services.GetRequiredService<IJSRuntime>();
var module = await js.InvokeAsync<IJSObjectReference>("import", "./js/scripts.js");

var culture = await module.InvokeAsync<string>("getCulture");

if (culture is not null)
{
    Culture.Current = new CultureInfo(culture);
}
else
{
    Culture.Current = Culture.Default;

    await module.InvokeVoidAsync("setCulture", Culture.Current.Name);
}
    
await module.DisposeAsync();

await host.RunAsync();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda