From 4cd6196dcaa456379f7ca89837f4d72163573728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 17 Dec 2019 15:01:22 +0300 Subject: [PATCH 01/13] Fixed #2410: ServiceProxyScript fails because of a missing route definition of the docs module --- .../Volo/Docs/Documents/DocsDocumentController.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs b/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs index dd60b2de06..9ff91c8b17 100644 --- a/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs +++ b/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs @@ -46,6 +46,8 @@ namespace Volo.Docs.Documents return DocumentAppService.GetResourceAsync(input); } + [HttpGet] + [Route("parameters")] public Task GetParametersAsync(GetParametersDocumentInput input) { return DocumentAppService.GetParametersAsync(input); From c15b05f9b449750c5bcf230293bc0a3d688e8e80 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 17 Dec 2019 15:25:27 +0300 Subject: [PATCH 02/13] Make emailadrdess required on identity domain --- .../Volo/Abp/Identity/IdentityUser.cs | 5 +++-- .../Volo/Abp/Identity/IdentityUserStore.cs | 3 ++- .../IdentityDbContextModelBuilderExtensions.cs | 2 +- .../AbpUsersDbContextModelCreatingExtensions.cs | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs index aca1535c3c..c6ad077456 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs @@ -130,16 +130,17 @@ namespace Volo.Abp.Identity ExtraProperties = new Dictionary(); } - public IdentityUser(Guid id, [NotNull] string userName, string email = null, Guid? tenantId = null) + public IdentityUser(Guid id, [NotNull] string userName, [NotNull] string email, Guid? tenantId = null) { Check.NotNull(userName, nameof(userName)); + Check.NotNull(email, nameof(email)); Id = id; TenantId = tenantId; UserName = userName; NormalizedUserName = userName.ToUpperInvariant(); Email = email; - NormalizedEmail = email?.ToUpperInvariant(); + NormalizedEmail = email.ToUpperInvariant(); ConcurrencyStamp = Guid.NewGuid().ToString(); SecurityStamp = Guid.NewGuid().ToString(); diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs index bac63a0c11..e92f31797d 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs @@ -597,11 +597,12 @@ namespace Volo.Abp.Identity /// The email to set. /// The used to propagate notifications that the operation should be canceled. /// The task object representing the asynchronous operation. - public virtual Task SetEmailAsync([NotNull] IdentityUser user, string email, CancellationToken cancellationToken = default) + public virtual Task SetEmailAsync([NotNull] IdentityUser user, [NotNull] string email, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); Check.NotNull(user, nameof(user)); + Check.NotNull(email, nameof(email)); user.Email = email; diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs index a2a63062d3..76ac038c05 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContextModelBuilderExtensions.cs @@ -29,7 +29,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore b.ConfigureAbpUser(); b.Property(u => u.NormalizedUserName).IsRequired().HasMaxLength(IdentityUserConsts.MaxNormalizedUserNameLength).HasColumnName(nameof(IdentityUser.NormalizedUserName)); - b.Property(u => u.NormalizedEmail).HasMaxLength(IdentityUserConsts.MaxNormalizedEmailLength).HasColumnName(nameof(IdentityUser.NormalizedEmail)); + b.Property(u => u.NormalizedEmail).IsRequired().HasMaxLength(IdentityUserConsts.MaxNormalizedEmailLength).HasColumnName(nameof(IdentityUser.NormalizedEmail)); b.Property(u => u.PasswordHash).HasMaxLength(IdentityUserConsts.MaxPasswordHashLength).HasColumnName(nameof(IdentityUser.PasswordHash)); b.Property(u => u.SecurityStamp).IsRequired().HasMaxLength(IdentityUserConsts.MaxSecurityStampLength).HasColumnName(nameof(IdentityUser.SecurityStamp)); b.Property(u => u.TwoFactorEnabled).HasDefaultValue(false).HasColumnName(nameof(IdentityUser.TwoFactorEnabled)); diff --git a/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/AbpUsersDbContextModelCreatingExtensions.cs b/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/AbpUsersDbContextModelCreatingExtensions.cs index 1b95984e4b..e8c95b5659 100644 --- a/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/AbpUsersDbContextModelCreatingExtensions.cs +++ b/modules/users/src/Volo.Abp.Users.EntityFrameworkCore/Volo/Abp/Users/EntityFrameworkCore/AbpUsersDbContextModelCreatingExtensions.cs @@ -10,7 +10,7 @@ namespace Volo.Abp.Users.EntityFrameworkCore { b.Property(u => u.TenantId).HasColumnName(nameof(IUser.TenantId)); b.Property(u => u.UserName).IsRequired().HasMaxLength(AbpUserConsts.MaxUserNameLength).HasColumnName(nameof(IUser.UserName)); - b.Property(u => u.Email).HasMaxLength(AbpUserConsts.MaxEmailLength).HasColumnName(nameof(IUser.Email)); + b.Property(u => u.Email).IsRequired().HasMaxLength(AbpUserConsts.MaxEmailLength).HasColumnName(nameof(IUser.Email)); b.Property(u => u.Name).HasMaxLength(AbpUserConsts.MaxNameLength).HasColumnName(nameof(IUser.Name)); b.Property(u => u.Surname).HasMaxLength(AbpUserConsts.MaxSurnameLength).HasColumnName(nameof(IUser.Surname)); b.Property(u => u.EmailConfirmed).HasDefaultValue(false).HasColumnName(nameof(IUser.EmailConfirmed)); From e46ec39a3e753575ed50ff54b1943ce9cb442b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 17 Dec 2019 16:04:41 +0300 Subject: [PATCH 03/13] Return NotFound on project not found. --- .../Pages/Documents/Project/Index.cshtml.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs index 0002a66343..b4ba841169 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs @@ -5,9 +5,11 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; +using Volo.Abp.Domain.Entities; using Volo.Abp.Localization; using Volo.Docs.Documents; using Volo.Docs.HtmlConverting; @@ -87,7 +89,15 @@ namespace Volo.Docs.Pages.Documents.Project DocumentsUrlPrefix = _uiOptions.RoutePrefix; ShowProjectsCombobox = _uiOptions.ShowProjectsCombobox; - await SetProjectAsync(); + try + { + await SetProjectAsync(); + } + catch (EntityNotFoundException e) + { + Logger.LogWarning(e.Message); + return NotFound(); + } if (ShowProjectsCombobox) { From 80a439cd5df48ec8ea27585304aa9e1deb0b5c87 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 17 Dec 2019 16:34:57 +0300 Subject: [PATCH 04/13] Move PostgreSQL-Integration document to a proper URL resolved https://github.com/abpframework/abp/issues/2408 --- ...gration.md => EntityFrameworkCore-PostgreSQL-Integration.md} | 0 docs/cs/docs-nav.json | 2 +- ...gration.md => EntityFrameworkCore-PostgreSQL-Integration.md} | 0 docs/en/docs-nav.json | 2 +- docs/pt-BR/docs-nav.json | 2 +- ...gration.md => EntityFrameworkCore-PostgreSQL-Integration.md} | 0 docs/zh-Hans/docs-nav.json | 2 +- 7 files changed, 4 insertions(+), 4 deletions(-) rename docs/cs/{Best-Practices/PostgreSQL-Integration.md => EntityFrameworkCore-PostgreSQL-Integration.md} (100%) rename docs/en/{Best-Practices/PostgreSQL-Integration.md => EntityFrameworkCore-PostgreSQL-Integration.md} (100%) rename docs/zh-Hans/{Best-Practices/PostgreSQL-Integration.md => EntityFrameworkCore-PostgreSQL-Integration.md} (100%) diff --git a/docs/cs/Best-Practices/PostgreSQL-Integration.md b/docs/cs/EntityFrameworkCore-PostgreSQL-Integration.md similarity index 100% rename from docs/cs/Best-Practices/PostgreSQL-Integration.md rename to docs/cs/EntityFrameworkCore-PostgreSQL-Integration.md diff --git a/docs/cs/docs-nav.json b/docs/cs/docs-nav.json index 8910c3b7f3..85cbf43c9d 100644 --- a/docs/cs/docs-nav.json +++ b/docs/cs/docs-nav.json @@ -264,7 +264,7 @@ "items": [ { "text": "PostgreSQL integrace", - "path": "Best-Practices/PostgreSQL-Integration.md" + "path": "EntityFrameworkCore-PostgreSQL-Integration.md" } ] }, diff --git a/docs/en/Best-Practices/PostgreSQL-Integration.md b/docs/en/EntityFrameworkCore-PostgreSQL-Integration.md similarity index 100% rename from docs/en/Best-Practices/PostgreSQL-Integration.md rename to docs/en/EntityFrameworkCore-PostgreSQL-Integration.md diff --git a/docs/en/docs-nav.json b/docs/en/docs-nav.json index 863290126a..db194177a9 100644 --- a/docs/en/docs-nav.json +++ b/docs/en/docs-nav.json @@ -265,7 +265,7 @@ "items": [ { "text": "PostgreSQL Integration", - "path": "Best-Practices/PostgreSQL-Integration.md" + "path": "EntityFrameworkCore-PostgreSQL-Integration.md" } ] }, diff --git a/docs/pt-BR/docs-nav.json b/docs/pt-BR/docs-nav.json index 90b29626b8..8e7eaf62af 100644 --- a/docs/pt-BR/docs-nav.json +++ b/docs/pt-BR/docs-nav.json @@ -249,7 +249,7 @@ "items": [ { "text": "Integração do PostgreSQL", - "path": "Best-Practices/PostgreSQL-Integration.md" + "path": "EntityFrameworkCore-PostgreSQL-Integration.md" } ] }, diff --git a/docs/zh-Hans/Best-Practices/PostgreSQL-Integration.md b/docs/zh-Hans/EntityFrameworkCore-PostgreSQL-Integration.md similarity index 100% rename from docs/zh-Hans/Best-Practices/PostgreSQL-Integration.md rename to docs/zh-Hans/EntityFrameworkCore-PostgreSQL-Integration.md diff --git a/docs/zh-Hans/docs-nav.json b/docs/zh-Hans/docs-nav.json index 3c6c58cd68..dd740f6c3b 100644 --- a/docs/zh-Hans/docs-nav.json +++ b/docs/zh-Hans/docs-nav.json @@ -254,7 +254,7 @@ "items": [ { "text": "PostgreSQL 集成", - "path": "Best-Practices/PostgreSQL-Integration.md" + "path": "EntityFrameworkCore-PostgreSQL-Integration.md" } ] }, From b04df4eff394bd5c30d0a058dbd62abdfbb1edd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 17 Dec 2019 19:00:00 +0300 Subject: [PATCH 05/13] Update AbpDictionaryBasedStringLocalizer.cs --- .../Volo/Abp/Localization/AbpDictionaryBasedStringLocalizer.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpDictionaryBasedStringLocalizer.cs b/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpDictionaryBasedStringLocalizer.cs index b1741d0ca0..d6b7073ee5 100644 --- a/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpDictionaryBasedStringLocalizer.cs +++ b/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/AbpDictionaryBasedStringLocalizer.cs @@ -31,8 +31,7 @@ namespace Volo.Abp.Localization includeParentCultures ); } - - + public IEnumerable GetAllStrings(bool includeParentCultures, bool includeBaseLocalizers) { return GetAllStrings( From fe2f66a30479a0e22247f3cc6f11c62bd1e10e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 17 Dec 2019 19:05:39 +0300 Subject: [PATCH 06/13] Eleminate AsyncHelper.RunSync usage from RemoteLocalizationContributor. --- .../CachedApplicationConfigurationClient.cs | 28 +++++++++++++++++++ .../ICachedApplicationConfigurationClient.cs | 2 ++ .../Client/RemoteLocalizationContributor.cs | 4 +-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClient.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClient.cs index 838150fd49..fc2ba3eb13 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClient.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClient.cs @@ -7,6 +7,7 @@ using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.Http.Client.DynamicProxying; +using Volo.Abp.Threading; using Volo.Abp.Users; namespace Volo.Abp.AspNetCore.Mvc.Client @@ -30,6 +31,33 @@ namespace Volo.Abp.AspNetCore.Mvc.Client Cache = cache; } + public ApplicationConfigurationDto Get() + { + var cacheKey = CreateCacheKey(); + var httpContext = HttpContextAccessor?.HttpContext; + + if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration) + { + return configuration; + } + + configuration = Cache.GetOrAdd( + cacheKey, + () => AsyncHelper.RunSync(Proxy.Service.GetAsync), + () => new DistributedCacheEntryOptions + { + AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(120) //TODO: Should be configurable. Default value should be higher (5 mins would be good). + } + ); + + if (httpContext != null) + { + httpContext.Items[cacheKey] = configuration; + } + + return configuration; + } + public async Task GetAsync() { var cacheKey = CreateCacheKey(); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/ICachedApplicationConfigurationClient.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/ICachedApplicationConfigurationClient.cs index 71d9d8cddf..00f195166c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/ICachedApplicationConfigurationClient.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/ICachedApplicationConfigurationClient.cs @@ -5,6 +5,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Client { public interface ICachedApplicationConfigurationClient { + ApplicationConfigurationDto Get(); + Task GetAsync(); } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs index 79033f3679..4b92f1083f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs @@ -55,9 +55,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Client private Dictionary GetResourceOrNull() { - var applicationConfigurationDto = AsyncHelper.RunSync( - () => _applicationConfigurationClient.GetAsync() - ); + var applicationConfigurationDto = _applicationConfigurationClient.Get(); var resource = applicationConfigurationDto .Localization.Values From 05cc1e2b2121d81762ae55d141238cde6845711e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 17 Dec 2019 19:35:13 +0300 Subject: [PATCH 07/13] Avoid AsyncHelper usage in the DefaultAbpRequestLocalizationOptionsProvider --- .../AbpRequestLocalizationMiddleware.cs | 4 +- ...ltAbpRequestLocalizationOptionsProvider.cs | 79 +++++++++++-------- .../IAbpRequestLocalizationOptionsProvider.cs | 3 +- 3 files changed, 49 insertions(+), 37 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationMiddleware.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationMiddleware.cs index 75d903557e..a7dfa5044c 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationMiddleware.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/AbpRequestLocalizationMiddleware.cs @@ -25,7 +25,9 @@ namespace Microsoft.AspNetCore.RequestLocalization { var middleware = new RequestLocalizationMiddleware( next, - new OptionsWrapper(_requestLocalizationOptionsProvider.GetLocalizationOptions()), + new OptionsWrapper( + await _requestLocalizationOptionsProvider.GetLocalizationOptionsAsync() + ), _loggerFactory ); diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/DefaultAbpRequestLocalizationOptionsProvider.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/DefaultAbpRequestLocalizationOptionsProvider.cs index 730f6e3937..c30eafb9d0 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/DefaultAbpRequestLocalizationOptionsProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/DefaultAbpRequestLocalizationOptionsProvider.cs @@ -2,67 +2,76 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Localization; using Microsoft.Extensions.DependencyInjection; +using Nito.AsyncEx; using Volo.Abp.DependencyInjection; using Volo.Abp.Localization; using Volo.Abp.Settings; -using Volo.Abp.Threading; namespace Microsoft.AspNetCore.RequestLocalization { public class DefaultAbpRequestLocalizationOptionsProvider : IAbpRequestLocalizationOptionsProvider, ISingletonDependency { - private readonly IServiceProvider _serviceProvider; - private Lazy _lazyRequestLocalizationOptions; + private readonly IServiceScopeFactory _serviceProviderFactory; + private readonly SemaphoreSlim _syncSemaphore; + private Action _optionsAction; + private RequestLocalizationOptions _requestLocalizationOptions; - public DefaultAbpRequestLocalizationOptionsProvider(IServiceProvider serviceProvider) + public DefaultAbpRequestLocalizationOptionsProvider(IServiceScopeFactory serviceProviderFactory) { - _serviceProvider = serviceProvider; + _serviceProviderFactory = serviceProviderFactory; + _syncSemaphore = new SemaphoreSlim(1, 1); } public void InitLocalizationOptions(Action optionsAction = null) { - _lazyRequestLocalizationOptions = new Lazy(() => + _optionsAction = optionsAction; + } + + public async Task GetLocalizationOptionsAsync() + { + if (_requestLocalizationOptions == null) { - using (var serviceScope = _serviceProvider.CreateScope()) + using (await _syncSemaphore.LockAsync()) { - var languageProvider = serviceScope.ServiceProvider.GetRequiredService(); - var settingProvider = serviceScope.ServiceProvider.GetRequiredService(); + using (var serviceScope = _serviceProviderFactory.CreateScope()) + { + var languageProvider = serviceScope.ServiceProvider.GetRequiredService(); + var settingProvider = serviceScope.ServiceProvider.GetRequiredService(); - var languages = AsyncHelper.RunSync(languageProvider.GetLanguagesAsync); - var defaultLanguage = AsyncHelper.RunSync(() => - settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage)); + var languages = await languageProvider.GetLanguagesAsync(); + var defaultLanguage = await settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage); - var options = !languages.Any() - ? new RequestLocalizationOptions() - : new RequestLocalizationOptions - { - DefaultRequestCulture = DefaultGetRequestCulture(defaultLanguage, languages), + var options = !languages.Any() + ? new RequestLocalizationOptions() + : new RequestLocalizationOptions + { + DefaultRequestCulture = DefaultGetRequestCulture(defaultLanguage, languages), - SupportedCultures = languages - .Select(l => l.CultureName) - .Distinct() - .Select(c => new CultureInfo(c)) - .ToArray(), + SupportedCultures = languages + .Select(l => l.CultureName) + .Distinct() + .Select(c => new CultureInfo(c)) + .ToArray(), - SupportedUICultures = languages - .Select(l => l.UiCultureName) - .Distinct() - .Select(c => new CultureInfo(c)) - .ToArray() - }; + SupportedUICultures = languages + .Select(l => l.UiCultureName) + .Distinct() + .Select(c => new CultureInfo(c)) + .ToArray() + }; - optionsAction?.Invoke(options); - return options; + _optionsAction?.Invoke(options); + _requestLocalizationOptions = options; + } } - }, true); - } + } - public RequestLocalizationOptions GetLocalizationOptions() - { - return _lazyRequestLocalizationOptions.Value; + return _requestLocalizationOptions; } private static RequestCulture DefaultGetRequestCulture(string defaultLanguage, IReadOnlyList languages) diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/IAbpRequestLocalizationOptionsProvider.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/IAbpRequestLocalizationOptionsProvider.cs index 5179bb48ee..86cd3153f7 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/IAbpRequestLocalizationOptionsProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/RequestLocalization/IAbpRequestLocalizationOptionsProvider.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; namespace Microsoft.AspNetCore.RequestLocalization @@ -7,6 +8,6 @@ namespace Microsoft.AspNetCore.RequestLocalization { void InitLocalizationOptions(Action optionsAction = null); - RequestLocalizationOptions GetLocalizationOptions(); + Task GetLocalizationOptionsAsync(); } } \ No newline at end of file From 647dd63e7e24f57dedb5bb47c3ce788fc12b66b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 17 Dec 2019 19:48:55 +0300 Subject: [PATCH 08/13] Make IJobQueueManager.Get method async to reduce AsyncHelper usage --- .../RabbitMQ/IJobQueueManager.cs | 5 +-- .../RabbitMQ/JobQueueManager.cs | 31 ++++++++++++++----- .../RabbitMQ/RabbitMqBackgroundJobManager.cs | 7 ++--- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/IJobQueueManager.cs b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/IJobQueueManager.cs index da560d1ed2..8cafb8c247 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/IJobQueueManager.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/IJobQueueManager.cs @@ -1,9 +1,10 @@ -using Volo.Abp.Threading; +using System.Threading.Tasks; +using Volo.Abp.Threading; namespace Volo.Abp.BackgroundJobs.RabbitMQ { public interface IJobQueueManager : IRunnable { - IJobQueue Get(); + Task> GetAsync(); } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueManager.cs b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueManager.cs index 73b7c21d2a..f07564ad5a 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueManager.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueueManager.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; +using Nito.AsyncEx; using Volo.Abp.DependencyInjection; using Volo.Abp.Threading; @@ -17,6 +18,8 @@ namespace Volo.Abp.BackgroundJobs.RabbitMQ protected AbpBackgroundJobOptions Options { get; } + protected SemaphoreSlim SyncSemaphore { get; } + public JobQueueManager( IOptions options, IServiceProvider serviceProvider) @@ -24,6 +27,7 @@ namespace Volo.Abp.BackgroundJobs.RabbitMQ ServiceProvider = serviceProvider; Options = options.Value; JobQueues = new ConcurrentDictionary(); + SyncSemaphore = new SemaphoreSlim(1, 1); } public async Task StartAsync(CancellationToken cancellationToken = default) @@ -51,20 +55,31 @@ namespace Volo.Abp.BackgroundJobs.RabbitMQ JobQueues.Clear(); } - public IJobQueue Get() + public async Task> GetAsync() { var jobConfiguration = Options.GetJob(typeof(TArgs)); - return (IJobQueue)JobQueues.GetOrAdd(jobConfiguration.JobName, _ => + if (JobQueues.TryGetValue(jobConfiguration.JobName, out var jobQueue)) + { + return (IJobQueue)jobQueue; + } + + using (await SyncSemaphore.LockAsync()) { - var jobQueue = (IRunnable) ServiceProvider - .GetRequiredService(typeof(IJobQueue<>) - .MakeGenericType(typeof(TArgs))); + if (JobQueues.TryGetValue(jobConfiguration.JobName, out jobQueue)) + { + return (IJobQueue)jobQueue; + } - AsyncHelper.RunSync(() => jobQueue.StartAsync()); + jobQueue = (IJobQueue)ServiceProvider + .GetRequiredService(typeof(IJobQueue<>).MakeGenericType(typeof(TArgs))); - return jobQueue; - }); + await jobQueue.StartAsync(); + + JobQueues.TryAdd(jobConfiguration.JobName, jobQueue); + + return (IJobQueue)jobQueue; + } } } } diff --git a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/RabbitMqBackgroundJobManager.cs b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/RabbitMqBackgroundJobManager.cs index c2976e43fb..f70d553128 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/RabbitMqBackgroundJobManager.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/RabbitMqBackgroundJobManager.cs @@ -14,14 +14,13 @@ namespace Volo.Abp.BackgroundJobs.RabbitMQ _jobQueueManager = jobQueueManager; } - public Task EnqueueAsync( + public async Task EnqueueAsync( TArgs args, BackgroundJobPriority priority = BackgroundJobPriority.Normal, TimeSpan? delay = null) { - return _jobQueueManager - .Get() - .EnqueueAsync(args, priority, delay); + var jobQueue = await _jobQueueManager.GetAsync(); + return await jobQueue.EnqueueAsync(args, priority, delay); } } } From 5fe88a3b094fcb5385cf448c7e90687d12a91851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 17 Dec 2019 22:16:07 +0300 Subject: [PATCH 09/13] Improve RemoteTenantStore: Reduce AsyncHelper usage. --- .../Mvc/Client/RemoteTenantStore.cs | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteTenantStore.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteTenantStore.cs index 718abbb6a9..236387823c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteTenantStore.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteTenantStore.cs @@ -85,12 +85,58 @@ namespace Volo.Abp.AspNetCore.Mvc.Client public TenantConfiguration Find(string name) { - return AsyncHelper.RunSync(() => FindAsync(name)); + var cacheKey = CreateCacheKey(name); + var httpContext = HttpContextAccessor?.HttpContext; + + if (httpContext != null && httpContext.Items[cacheKey] is TenantConfiguration tenantConfiguration) + { + return tenantConfiguration; + } + + tenantConfiguration = Cache.GetOrAdd( + cacheKey, + () => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByNameAsync(name))), + () => new DistributedCacheEntryOptions + { + AbsoluteExpirationRelativeToNow = + TimeSpan.FromMinutes(5) //TODO: Should be configurable. + } + ); + + if (httpContext != null) + { + httpContext.Items[cacheKey] = tenantConfiguration; + } + + return tenantConfiguration; } public TenantConfiguration Find(Guid id) { - return AsyncHelper.RunSync(() => FindAsync(id)); + var cacheKey = CreateCacheKey(id); + var httpContext = HttpContextAccessor?.HttpContext; + + if (httpContext != null && httpContext.Items[cacheKey] is TenantConfiguration tenantConfiguration) + { + return tenantConfiguration; + } + + tenantConfiguration = Cache.GetOrAdd( + cacheKey, + () => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByIdAsync(id))), + () => new DistributedCacheEntryOptions + { + AbsoluteExpirationRelativeToNow = + TimeSpan.FromMinutes(5) //TODO: Should be configurable. + } + ); + + if (httpContext != null) + { + httpContext.Items[cacheKey] = tenantConfiguration; + } + + return tenantConfiguration; } protected virtual TenantConfiguration CreateTenantConfiguration(FindTenantResultDto tenantResultDto) From e111ca3675ad4aac207996bec3fdeb3441237d0b Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 18 Dec 2019 12:44:15 +0300 Subject: [PATCH 10/13] template migrations re-initial because of https://github.com/abpframework/abp/issues/2389 --- ...itial.Designer.cs => 20191218090017_Initial.Designer.cs} | 6 ++++-- ...{20191022082740_Initial.cs => 20191218090017_Initial.cs} | 4 ++-- .../MyProjectNameMigrationsDbContextModelSnapshot.cs | 4 +++- ...itial.Designer.cs => 20191218090727_Initial.Designer.cs} | 6 ++++-- ...{20191127123650_Initial.cs => 20191218090727_Initial.cs} | 4 ++-- .../Migrations/UnifiedDbContextModelSnapshot.cs | 4 +++- 6 files changed, 18 insertions(+), 10 deletions(-) rename templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/{20191022082740_Initial.Designer.cs => 20191218090017_Initial.Designer.cs} (99%) rename templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/{20191022082740_Initial.cs => 20191218090017_Initial.cs} (99%) rename templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/{20191127123650_Initial.Designer.cs => 20191218090727_Initial.Designer.cs} (99%) rename templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/{20191127123650_Initial.cs => 20191218090727_Initial.cs} (99%) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191022082740_Initial.Designer.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191218090017_Initial.Designer.cs similarity index 99% rename from templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191022082740_Initial.Designer.cs rename to templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191218090017_Initial.Designer.cs index 6a8434f997..282d8490be 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191022082740_Initial.Designer.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191218090017_Initial.Designer.cs @@ -10,14 +10,14 @@ using MyCompanyName.MyProjectName.EntityFrameworkCore; namespace MyCompanyName.MyProjectName.Migrations { [DbContext(typeof(MyProjectNameMigrationsDbContext))] - [Migration("20191022082740_Initial")] + [Migration("20191218090017_Initial")] partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.0.0") + .HasAnnotation("ProductVersion", "3.1.0") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); @@ -512,6 +512,7 @@ namespace MyCompanyName.MyProjectName.Migrations .HasColumnType("datetime2"); b.Property("Email") + .IsRequired() .HasColumnName("Email") .HasColumnType("nvarchar(256)") .HasMaxLength(256); @@ -555,6 +556,7 @@ namespace MyCompanyName.MyProjectName.Migrations .HasMaxLength(64); b.Property("NormalizedEmail") + .IsRequired() .HasColumnName("NormalizedEmail") .HasColumnType("nvarchar(256)") .HasMaxLength(256); diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191022082740_Initial.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191218090017_Initial.cs similarity index 99% rename from templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191022082740_Initial.cs rename to templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191218090017_Initial.cs index f481916966..c7b0e07a56 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191022082740_Initial.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/20191218090017_Initial.cs @@ -184,8 +184,8 @@ namespace MyCompanyName.MyProjectName.Migrations NormalizedUserName = table.Column(maxLength: 256, nullable: false), Name = table.Column(maxLength: 64, nullable: true), Surname = table.Column(maxLength: 64, nullable: true), - Email = table.Column(maxLength: 256, nullable: true), - NormalizedEmail = table.Column(maxLength: 256, nullable: true), + Email = table.Column(maxLength: 256, nullable: false), + NormalizedEmail = table.Column(maxLength: 256, nullable: false), EmailConfirmed = table.Column(nullable: false, defaultValue: false), PasswordHash = table.Column(maxLength: 256, nullable: true), SecurityStamp = table.Column(maxLength: 256, nullable: false), diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/MyProjectNameMigrationsDbContextModelSnapshot.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/MyProjectNameMigrationsDbContextModelSnapshot.cs index 81cc4958d2..460515931f 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/MyProjectNameMigrationsDbContextModelSnapshot.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations/Migrations/MyProjectNameMigrationsDbContextModelSnapshot.cs @@ -15,7 +15,7 @@ namespace MyCompanyName.MyProjectName.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.0.0") + .HasAnnotation("ProductVersion", "3.1.0") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); @@ -510,6 +510,7 @@ namespace MyCompanyName.MyProjectName.Migrations .HasColumnType("datetime2"); b.Property("Email") + .IsRequired() .HasColumnName("Email") .HasColumnType("nvarchar(256)") .HasMaxLength(256); @@ -553,6 +554,7 @@ namespace MyCompanyName.MyProjectName.Migrations .HasMaxLength(64); b.Property("NormalizedEmail") + .IsRequired() .HasColumnName("NormalizedEmail") .HasColumnType("nvarchar(256)") .HasMaxLength(256); diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191127123650_Initial.Designer.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191218090727_Initial.Designer.cs similarity index 99% rename from templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191127123650_Initial.Designer.cs rename to templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191218090727_Initial.Designer.cs index 4a9904eeec..5ce29ab888 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191127123650_Initial.Designer.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191218090727_Initial.Designer.cs @@ -10,14 +10,14 @@ using MyCompanyName.MyProjectName.EntityFrameworkCore; namespace MyCompanyName.MyProjectName.Migrations { [DbContext(typeof(UnifiedDbContext))] - [Migration("20191127123650_Initial")] + [Migration("20191218090727_Initial")] partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.0.0") + .HasAnnotation("ProductVersion", "3.1.0") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); @@ -426,6 +426,7 @@ namespace MyCompanyName.MyProjectName.Migrations .HasColumnType("datetime2"); b.Property("Email") + .IsRequired() .HasColumnName("Email") .HasColumnType("nvarchar(256)") .HasMaxLength(256); @@ -469,6 +470,7 @@ namespace MyCompanyName.MyProjectName.Migrations .HasMaxLength(64); b.Property("NormalizedEmail") + .IsRequired() .HasColumnName("NormalizedEmail") .HasColumnType("nvarchar(256)") .HasMaxLength(256); diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191127123650_Initial.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191218090727_Initial.cs similarity index 99% rename from templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191127123650_Initial.cs rename to templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191218090727_Initial.cs index 8e851efc0a..50aaa468b2 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191127123650_Initial.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/20191218090727_Initial.cs @@ -148,8 +148,8 @@ namespace MyCompanyName.MyProjectName.Migrations NormalizedUserName = table.Column(maxLength: 256, nullable: false), Name = table.Column(maxLength: 64, nullable: true), Surname = table.Column(maxLength: 64, nullable: true), - Email = table.Column(maxLength: 256, nullable: true), - NormalizedEmail = table.Column(maxLength: 256, nullable: true), + Email = table.Column(maxLength: 256, nullable: false), + NormalizedEmail = table.Column(maxLength: 256, nullable: false), EmailConfirmed = table.Column(nullable: false, defaultValue: false), PasswordHash = table.Column(maxLength: 256, nullable: true), SecurityStamp = table.Column(maxLength: 256, nullable: false), diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs index dfdc590b6f..2f58731622 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs @@ -15,7 +15,7 @@ namespace MyCompanyName.MyProjectName.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.0.0") + .HasAnnotation("ProductVersion", "3.1.0") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); @@ -424,6 +424,7 @@ namespace MyCompanyName.MyProjectName.Migrations .HasColumnType("datetime2"); b.Property("Email") + .IsRequired() .HasColumnName("Email") .HasColumnType("nvarchar(256)") .HasMaxLength(256); @@ -467,6 +468,7 @@ namespace MyCompanyName.MyProjectName.Migrations .HasMaxLength(64); b.Property("NormalizedEmail") + .IsRequired() .HasColumnName("NormalizedEmail") .HasColumnType("nvarchar(256)") .HasMaxLength(256); From 67331bce5fea9aac27ef34db2b2914b80f2270ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 18 Dec 2019 13:24:49 +0300 Subject: [PATCH 11/13] Added debug log to AbpApplicationConfigurationAppService --- .../AbpApplicationConfigurationAppService.cs | 20 ++++++++++++++++++- ...pplicationConfigurationScriptController.cs | 14 ++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs index f3af9182ba..542daecd27 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; using Volo.Abp.Application.Services; using Volo.Abp.Authorization; using Volo.Abp.Features; @@ -34,7 +35,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations IAuthorizationService authorizationService, ICurrentUser currentUser, ISettingProvider settingProvider, - SettingDefinitionManager settingDefinitionManager, + ISettingDefinitionManager settingDefinitionManager, IFeatureDefinitionManager featureDefinitionManager, ILanguageProvider languageProvider) { @@ -76,6 +77,9 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations protected virtual async Task GetAuthConfigAsync() { + Logger.LogDebug("Executing AbpApplicationConfigurationAppService.GetAuthConfigAsync()"); + + var authConfig = new ApplicationAuthConfigurationDto(); foreach (var policyName in await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync()) @@ -88,11 +92,15 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations } } + Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetAuthConfigAsync()"); + return authConfig; } protected virtual async Task GetLocalizationConfigAsync() { + Logger.LogDebug("Executing AbpApplicationConfigurationAppService.GetLocalizationConfigAsync()"); + var localizationConfig = new ApplicationLocalizationConfigurationDto(); localizationConfig.Languages.AddRange(await _languageProvider.GetLanguagesAsync()); @@ -115,6 +123,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations localizationConfig.CurrentCulture = GetCurrentCultureInfo(); + Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetLocalizationConfigAsync()"); + return localizationConfig; } @@ -145,6 +155,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations private async Task GetSettingConfigAsync() { + Logger.LogDebug("Executing AbpApplicationConfigurationAppService.GetSettingConfigAsync()"); + var result = new ApplicationSettingConfigurationDto { Values = new Dictionary() @@ -160,11 +172,15 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations result.Values[settingDefinition.Name] = await _settingProvider.GetOrNullAsync(settingDefinition.Name); } + Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetSettingConfigAsync()"); + return result; } protected virtual async Task GetFeaturesConfigAsync() { + Logger.LogDebug("Executing AbpApplicationConfigurationAppService.GetFeaturesConfigAsync()"); + var result = new ApplicationFeatureConfigurationDto(); foreach (var featureDefinition in _featureDefinitionManager.GetAll()) @@ -177,6 +193,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations result.Values[featureDefinition.Name] = await FeatureChecker.GetOrNullAsync(featureDefinition.Name); } + Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetFeaturesConfigAsync()"); + return result; } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationScriptController.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationScriptController.cs index bce46bab44..da5dbe902b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationScriptController.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationScriptController.cs @@ -2,6 +2,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using Volo.Abp.Auditing; using Volo.Abp.Http; using Volo.Abp.Json; @@ -28,12 +29,15 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations [Produces(MimeTypes.Application.Javascript, MimeTypes.Text.Plain)] public async Task Get() { - return Content( - CreateAbpExtendScript( - await _configurationAppService.GetAsync() - ), - MimeTypes.Application.Javascript + Logger.LogDebug("Executing AbpApplicationConfigurationScriptController.Get()"); + + var result = CreateAbpExtendScript( + await _configurationAppService.GetAsync() ); + + Logger.LogDebug("Executed AbpApplicationConfigurationScriptController.Get()"); + + return Content(result, MimeTypes.Application.Javascript); } private string CreateAbpExtendScript(ApplicationConfigurationDto config) From 66122369ca5abedc3f3cd80089dbfab77ae7378b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 18 Dec 2019 13:58:58 +0300 Subject: [PATCH 12/13] Added log for AbpApplicationConfigurationAppService --- .../AbpApplicationConfigurationAppService.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs index 542daecd27..5015d146e8 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs @@ -79,13 +79,18 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations { Logger.LogDebug("Executing AbpApplicationConfigurationAppService.GetAuthConfigAsync()"); - var authConfig = new ApplicationAuthConfigurationDto(); - foreach (var policyName in await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync()) + var policyNames = await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync(); + + Logger.LogDebug($"GetPoliciesNamesAsync returns {policyNames.Count} items."); + + foreach (var policyName in policyNames) { authConfig.Policies[policyName] = true; + Logger.LogDebug($"_authorizationService.IsGrantedAsync? {policyName}"); + if (await _authorizationService.IsGrantedAsync(policyName)) { authConfig.GrantedPolicies[policyName] = true; @@ -130,7 +135,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations private static CurrentCultureDto GetCurrentCultureInfo() { - return new CurrentCultureDto + return new CurrentCultureDto { Name = CultureInfo.CurrentUICulture.Name, DisplayName = CultureInfo.CurrentUICulture.DisplayName, @@ -173,7 +178,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations } Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetSettingConfigAsync()"); - + return result; } From 6e6070ab72343c83c496554cd7f8928951364c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 18 Dec 2019 14:12:19 +0300 Subject: [PATCH 13/13] Don't pass authorizationService.AsAbpAuthorizationService().CurrentPrincipal as the resource --- .../AbpAuthorizationServiceExtensions.cs | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/framework/src/Volo.Abp.Authorization/Microsoft/AspNetCore/Authorization/AbpAuthorizationServiceExtensions.cs b/framework/src/Volo.Abp.Authorization/Microsoft/AspNetCore/Authorization/AbpAuthorizationServiceExtensions.cs index 9d16a6a55c..d682d4f0c8 100644 --- a/framework/src/Volo.Abp.Authorization/Microsoft/AspNetCore/Authorization/AbpAuthorizationServiceExtensions.cs +++ b/framework/src/Volo.Abp.Authorization/Microsoft/AspNetCore/Authorization/AbpAuthorizationServiceExtensions.cs @@ -7,52 +7,54 @@ namespace Microsoft.AspNetCore.Authorization { public static class AbpAuthorizationServiceExtensions { - public static Task AuthorizeAsync(this IAuthorizationService authorizationService, string policyName) + public static async Task AuthorizeAsync(this IAuthorizationService authorizationService, string policyName) { - return AuthorizeAsync( + return await AuthorizeAsync( authorizationService, - authorizationService.AsAbpAuthorizationService().CurrentPrincipal, + null, policyName ); } - public static Task AuthorizeAsync(this IAuthorizationService authorizationService, object resource, IAuthorizationRequirement requirement) + public static async Task AuthorizeAsync(this IAuthorizationService authorizationService, object resource, IAuthorizationRequirement requirement) { - return authorizationService.AuthorizeAsync( + return await authorizationService.AuthorizeAsync( authorizationService.AsAbpAuthorizationService().CurrentPrincipal, resource, requirement ); } - public static Task AuthorizeAsync(this IAuthorizationService authorizationService, object resource, AuthorizationPolicy policy) + public static async Task AuthorizeAsync(this IAuthorizationService authorizationService, object resource, AuthorizationPolicy policy) { - return authorizationService.AuthorizeAsync( + return await authorizationService.AuthorizeAsync( authorizationService.AsAbpAuthorizationService().CurrentPrincipal, resource, policy ); } - public static Task AuthorizeAsync(this IAuthorizationService authorizationService, AuthorizationPolicy policy) + public static async Task AuthorizeAsync(this IAuthorizationService authorizationService, AuthorizationPolicy policy) { - return AuthorizeAsync(authorizationService, authorizationService.AsAbpAuthorizationService().CurrentPrincipal, + return await AuthorizeAsync( + authorizationService, + null, policy ); } - public static Task AuthorizeAsync(this IAuthorizationService authorizationService, object resource, IEnumerable requirements) + public static async Task AuthorizeAsync(this IAuthorizationService authorizationService, object resource, IEnumerable requirements) { - return authorizationService.AuthorizeAsync( + return await authorizationService.AuthorizeAsync( authorizationService.AsAbpAuthorizationService().CurrentPrincipal, resource, requirements ); } - public static Task AuthorizeAsync(this IAuthorizationService authorizationService, object resource, string policyName) + public static async Task AuthorizeAsync(this IAuthorizationService authorizationService, object resource, string policyName) { - return authorizationService.AuthorizeAsync( + return await authorizationService.AuthorizeAsync( authorizationService.AsAbpAuthorizationService().CurrentPrincipal, resource, policyName