From eb5ef0d747bfb521454e8e9419cb5d3b382867ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 13 Sep 2020 16:27:14 +0300 Subject: [PATCH] Moved async init code to the framework. --- .../AbpWebAssemblyHostBuilderExtensions.cs | 20 +++++++++++++++++++ ...pApplicationWithExternalServiceProvider.cs | 2 +- .../Program.cs | 11 +--------- 3 files changed, 22 insertions(+), 11 deletions(-) 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 0dec7d406f..865a6f0edc 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 @@ -1,9 +1,12 @@ using System; +using System.Reflection; +using System.Threading.Tasks; using JetBrains.Annotations; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Volo.Abp; using Volo.Abp.AspNetCore.Components.WebAssembly; +using Volo.Abp.AspNetCore.Mvc.Client; using Volo.Abp.Modularity; namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting @@ -27,5 +30,22 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting return application; } + + public static async Task InitializeAsync( + [NotNull] this IAbpApplicationWithExternalServiceProvider application, + [NotNull] IServiceProvider serviceProvider) + { + Check.NotNull(application, nameof(application)); + Check.NotNull(serviceProvider, nameof(serviceProvider)); + + application.Initialize(serviceProvider); + + using (var scope = serviceProvider.CreateScope()) + { + await scope.ServiceProvider + .GetRequiredService() + .InitializeAsync(); + } + } } } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplicationWithExternalServiceProvider.cs b/framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplicationWithExternalServiceProvider.cs index 1c522a438a..8968fdf918 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplicationWithExternalServiceProvider.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/IAbpApplicationWithExternalServiceProvider.cs @@ -7,4 +7,4 @@ namespace Volo.Abp { void Initialize([NotNull] IServiceProvider serviceProvider); } -} \ No newline at end of file +} diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Program.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Program.cs index 1956788154..31f1c228ad 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Program.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/Program.cs @@ -1,7 +1,5 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.AspNetCore.Mvc.Client; namespace MyCompanyName.MyProjectName.Blazor { @@ -18,14 +16,7 @@ namespace MyCompanyName.MyProjectName.Blazor var host = builder.Build(); - application.Initialize(host.Services); - - using (var scope = host.Services.CreateScope()) - { - await scope.ServiceProvider - .GetRequiredService() - .InitializeAsync(); - } + await application.InitializeAsync(host.Services); await host.RunAsync(); }