From 9ee07d7019f216e5e8eddf3a9a678897a0c3572d Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 20 Dec 2021 20:18:46 +0800 Subject: [PATCH] Update AbpWebAssemblyHostBuilderExtensions.cs --- .../AbpWebAssemblyHostBuilderExtensions.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Microsoft/AspNetCore/Components/WebAssembly/Hosting/AbpWebAssemblyHostBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Microsoft/AspNetCore/Components/WebAssembly/Hosting/AbpWebAssemblyHostBuilderExtensions.cs index cb104533cb..7c4ff4a868 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Microsoft/AspNetCore/Components/WebAssembly/Hosting/AbpWebAssemblyHostBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Microsoft/AspNetCore/Components/WebAssembly/Hosting/AbpWebAssemblyHostBuilderExtensions.cs @@ -17,6 +17,30 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting; public static class AbpWebAssemblyHostBuilderExtensions { + public static async Task AddApplicationAsync( + [NotNull] this WebAssemblyHostBuilder builder, + Action options) + where TStartupModule : IAbpModule + { + Check.NotNull(builder, nameof(builder)); + + // Related this commit(https://github.com/dotnet/aspnetcore/commit/b99d805bc037fcac56afb79abeb7d5a43141c85e) + // Microsoft.AspNetCore.Blazor.BuildTools has been removed in net 5.0. + // This call may be removed when we find a suitable solution. + // System.Runtime.CompilerServices.AsyncStateMachineAttribute + Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add(); + + builder.Services.AddSingleton(builder.Configuration); + builder.Services.AddSingleton(builder); + + var application = await builder.Services.AddApplicationAsync(opts => + { + options?.Invoke(new AbpWebAssemblyApplicationCreationOptions(builder, opts)); + }); + + return application; + } + public static IAbpApplicationWithExternalServiceProvider AddApplication( [NotNull] this WebAssemblyHostBuilder builder, Action options) @@ -51,7 +75,7 @@ public static class AbpWebAssemblyHostBuilderExtensions ((ComponentsClientScopeServiceProviderAccessor)serviceProvider .GetRequiredService()).ServiceProvider = serviceProvider; - application.Initialize(serviceProvider); + await application.InitializeAsync(serviceProvider); await InitializeModulesAsync(serviceProvider); await SetCurrentLanguageAsync(serviceProvider); }