Merge pull request #12932 from abpframework/IAsyncInitialize

Remove `IAsyncInitialize` interface.
pull/12945/head
Halil İbrahim Kalkan 3 years ago committed by GitHub
commit 159ad23207
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,8 +1,11 @@
using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.AspNetCore.Components.DependencyInjection;
using Volo.Abp.AspNetCore.Components.Web.Security;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
using Volo.Abp.UI;
namespace Volo.Abp.AspNetCore.Components.Web;
@ -22,4 +25,14 @@ public class AbpAspNetCoreComponentsWebModule : AbpModule
{
context.Services.Replace(ServiceDescriptor.Transient<IComponentActivator, ServiceProviderComponentActivator>());
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
AsyncHelper.RunSync(() => OnApplicationInitializationAsync(context));
}
public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{
await context.ServiceProvider.GetRequiredService<AbpComponentsClaimsCache>().InitializeAsync();
}
}

@ -7,11 +7,7 @@ using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.Security;
[ExposeServices(
typeof(AbpComponentsClaimsCache),
typeof(IAsyncInitialize)
)]
public class AbpComponentsClaimsCache : IScopedDependency, IAsyncInitialize
public class AbpComponentsClaimsCache : IScopedDependency
{
public ClaimsPrincipal Principal { get; private set; }

@ -1,15 +1,12 @@
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.AspNetCore.Components.Web;
using Volo.Abp.AspNetCore.Components.Web.DependencyInjection;
using Volo.Abp.AspNetCore.Components.WebAssembly;
using Volo.Abp.AspNetCore.Mvc.Client;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Modularity;
@ -76,34 +73,5 @@ public static class AbpWebAssemblyHostBuilderExtensions
.GetRequiredService<IClientScopeServiceProviderAccessor>()).ServiceProvider = serviceProvider;
await application.InitializeAsync(serviceProvider);
await InitializeModulesAsync(serviceProvider);
await SetCurrentLanguageAsync(serviceProvider);
}
private async static Task InitializeModulesAsync(IServiceProvider serviceProvider)
{
foreach (var service in serviceProvider.GetServices<IAsyncInitialize>())
{
await service.InitializeAsync();
}
}
private async static Task SetCurrentLanguageAsync(IServiceProvider serviceProvider)
{
var configurationClient = serviceProvider.GetRequiredService<ICachedApplicationConfigurationClient>();
var utilsService = serviceProvider.GetRequiredService<IAbpUtilsService>();
var configuration = await configurationClient.GetAsync();
var cultureName = configuration.Localization?.CurrentCulture?.CultureName;
if (!cultureName.IsNullOrEmpty())
{
var culture = new CultureInfo(cultureName);
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
}
if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)
{
await utilsService.AddClassToTagAsync("body", "rtl");
}
}
}

@ -1,10 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Volo.Abp.AspNetCore.Components.Web;
using Volo.Abp.AspNetCore.Components.Web.ExceptionHandling;
using Volo.Abp.AspNetCore.Mvc.Client;
using Volo.Abp.Http.Client;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
using Volo.Abp.UI;
namespace Volo.Abp.AspNetCore.Components.WebAssembly;
@ -33,4 +37,34 @@ public class AbpAspNetCoreComponentsWebAssemblyModule : AbpModule
.GetHostBuilder().Logging
.AddProvider(new AbpExceptionHandlingLoggerProvider(context.Services));
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
AsyncHelper.RunSync(() => OnApplicationInitializationAsync(context));
}
public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{
await context.ServiceProvider.GetRequiredService<WebAssemblyCachedApplicationConfigurationClient>().InitializeAsync();
await SetCurrentLanguageAsync(context.ServiceProvider);
}
private async static Task SetCurrentLanguageAsync(IServiceProvider serviceProvider)
{
var configurationClient = serviceProvider.GetRequiredService<ICachedApplicationConfigurationClient>();
var utilsService = serviceProvider.GetRequiredService<IAbpUtilsService>();
var configuration = await configurationClient.GetAsync();
var cultureName = configuration.Localization?.CurrentCulture?.CultureName;
if (!cultureName.IsNullOrEmpty())
{
var culture = new CultureInfo(cultureName);
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
}
if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)
{
await utilsService.AddClassToTagAsync("body", "rtl");
}
}
}

@ -7,11 +7,6 @@ using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AspNetCore.Components.WebAssembly;
[ExposeServices(
typeof(WebAssemblyCachedApplicationConfigurationClient),
typeof(ICachedApplicationConfigurationClient),
typeof(IAsyncInitialize)
)]
public class WebAssemblyCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency
{
protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; }

@ -3,7 +3,7 @@ using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
namespace Volo.Abp.AspNetCore.Mvc.Client;
public interface ICachedApplicationConfigurationClient : IAsyncInitialize
public interface ICachedApplicationConfigurationClient
{
Task<ApplicationConfigurationDto> GetAsync();

@ -1,5 +1,8 @@
using Volo.Abp.EventBus;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EventBus;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Abp.AspNetCore.Mvc.Client;
@ -9,4 +12,13 @@ namespace Volo.Abp.AspNetCore.Mvc.Client;
)]
public class AbpAspNetCoreMvcClientModule : AbpModule
{
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
AsyncHelper.RunSync(() => OnApplicationInitializationAsync(context));
}
public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{
await context.ServiceProvider.GetRequiredService<MvcCachedApplicationConfigurationClient>().InitializeAsync();
}
}

@ -11,11 +11,6 @@ using Volo.Abp.Users;
namespace Volo.Abp.AspNetCore.Mvc.Client;
[ExposeServices(
typeof(MvcCachedApplicationConfigurationClient),
typeof(ICachedApplicationConfigurationClient),
typeof(IAsyncInitialize)
)]
public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency
{
protected IHttpContextAccessor HttpContextAccessor { get; }

@ -1,12 +0,0 @@
using System.Threading.Tasks;
namespace Volo.Abp;
/// <summary>
/// IMPORTANT: THIS IS AN INTERNAL CLASS TO BE USED BY THE ABP FRAMEWORK.
/// IT WILL BE REMOVED IN THE FUTURE VERSIONS. DON'T USE IT!
/// </summary>
public interface IAsyncInitialize //TODO: Remove once we have async module initialization
{
Task InitializeAsync();
}
Loading…
Cancel
Save