From 575d6bda54408d80d88af27fcddd8e61e6194f86 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 4 Apr 2019 15:38:45 +0300 Subject: [PATCH 1/4] Introduce IDistributedCacheSerializer and implement as Utf8JsonDistributedCacheSerializer --- .../Volo.Abp.Caching/Volo.Abp.Caching.csproj | 1 + .../Volo/Abp/Caching/AbpCachingModule.cs | 9 ++++--- .../Volo/Abp/Caching/DistributedCache.cs | 22 ++++++++-------- .../Caching/IDistributedCacheSerializer.cs | 9 +++++++ .../Utf8JsonDistributedCacheSerializer.cs | 26 +++++++++++++++++++ 5 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 framework/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCacheSerializer.cs create mode 100644 framework/src/Volo.Abp.Caching/Volo/Abp/Caching/Utf8JsonDistributedCacheSerializer.cs diff --git a/framework/src/Volo.Abp.Caching/Volo.Abp.Caching.csproj b/framework/src/Volo.Abp.Caching/Volo.Abp.Caching.csproj index e9a5acd990..f4417ae910 100644 --- a/framework/src/Volo.Abp.Caching/Volo.Abp.Caching.csproj +++ b/framework/src/Volo.Abp.Caching/Volo.Abp.Caching.csproj @@ -18,6 +18,7 @@ + diff --git a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/AbpCachingModule.cs b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/AbpCachingModule.cs index 3a1537cba7..48d55cc0d5 100644 --- a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/AbpCachingModule.cs +++ b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/AbpCachingModule.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using System; +using Volo.Abp.Json; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; using Volo.Abp.Serialization; @@ -7,9 +8,11 @@ using Volo.Abp.Threading; namespace Volo.Abp.Caching { - [DependsOn(typeof(AbpThreadingModule))] - [DependsOn(typeof(AbpSerializationModule))] - [DependsOn(typeof(AbpMultiTenancyModule))] + [DependsOn( + typeof(AbpThreadingModule), + typeof(AbpSerializationModule), + typeof(AbpMultiTenancyModule), + typeof(AbpJsonModule))] public class AbpCachingModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) diff --git a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs index 712a350108..75b024740c 100644 --- a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs +++ b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs @@ -25,11 +25,12 @@ namespace Volo.Abp.Caching protected ICancellationTokenProvider CancellationTokenProvider { get; } - protected IObjectSerializer ObjectSerializer { get; } + //TODO: Create IDistributedCacheSerializer + protected IDistributedCacheSerializer Serializer { get; } protected ICurrentTenant CurrentTenant { get; } - protected AsyncLock AsyncLock { get; } = new AsyncLock(); + //protected AsyncLock AsyncLock { get; } = new AsyncLock(); protected DistributedCacheEntryOptions DefaultCacheOptions; @@ -42,8 +43,7 @@ namespace Volo.Abp.Caching IOptions distributedCacheOption, IDistributedCache cache, ICancellationTokenProvider cancellationTokenProvider, - - IObjectSerializer objectSerializer, + IDistributedCacheSerializer serializer, ICurrentTenant currentTenant) { _distributedCacheOption = distributedCacheOption.Value; @@ -51,7 +51,7 @@ namespace Volo.Abp.Caching Cache = cache; CancellationTokenProvider = cancellationTokenProvider; Logger = NullLogger>.Instance; - ObjectSerializer = objectSerializer; + Serializer = serializer; CurrentTenant = currentTenant; SetDefaultOptions(); @@ -85,7 +85,7 @@ namespace Volo.Abp.Caching return null; } - return ObjectSerializer.Deserialize(cachedBytes); + return Serializer.Deserialize(cachedBytes); } public virtual async Task GetAsync( @@ -120,7 +120,7 @@ namespace Volo.Abp.Caching return null; } - return ObjectSerializer.Deserialize(cachedBytes); + return Serializer.Deserialize(cachedBytes); } public TCacheItem GetOrAdd( @@ -135,7 +135,7 @@ namespace Volo.Abp.Caching return value; } - using (AsyncLock.Lock(CancellationTokenProvider.Token)) + //using (AsyncLock.Lock(CancellationTokenProvider.Token)) { value = Get(key, hideErrors); if (value != null) @@ -164,7 +164,7 @@ namespace Volo.Abp.Caching return value; } - using (await AsyncLock.LockAsync(token)) + //using (await AsyncLock.LockAsync(token)) { value = await GetAsync(key, hideErrors, token); if (value != null) @@ -191,7 +191,7 @@ namespace Volo.Abp.Caching { Cache.Set( NormalizeKey(key), - ObjectSerializer.Serialize(value), + Serializer.Serialize(value), options ?? DefaultCacheOptions ); } @@ -220,7 +220,7 @@ namespace Volo.Abp.Caching { await Cache.SetAsync( NormalizeKey(key), - ObjectSerializer.Serialize(value), + Serializer.Serialize(value), options ?? DefaultCacheOptions, CancellationTokenProvider.FallbackToProvider(token) ); diff --git a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCacheSerializer.cs b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCacheSerializer.cs new file mode 100644 index 0000000000..a26620f17c --- /dev/null +++ b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCacheSerializer.cs @@ -0,0 +1,9 @@ +namespace Volo.Abp.Caching +{ + public interface IDistributedCacheSerializer + { + byte[] Serialize(T obj); + + T Deserialize(byte[] bytes); + } +} diff --git a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/Utf8JsonDistributedCacheSerializer.cs b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/Utf8JsonDistributedCacheSerializer.cs new file mode 100644 index 0000000000..a99127098f --- /dev/null +++ b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/Utf8JsonDistributedCacheSerializer.cs @@ -0,0 +1,26 @@ +using System.Text; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Json; + +namespace Volo.Abp.Caching +{ + public class Utf8JsonDistributedCacheSerializer : IDistributedCacheSerializer, ITransientDependency + { + protected IJsonSerializer JsonSerializer { get; } + + public Utf8JsonDistributedCacheSerializer(IJsonSerializer jsonSerializer) + { + JsonSerializer = jsonSerializer; + } + + public byte[] Serialize(T obj) + { + return Encoding.UTF8.GetBytes(JsonSerializer.Serialize(obj)); + } + + public T Deserialize(byte[] bytes) + { + return (T)JsonSerializer.Deserialize(typeof(T), Encoding.UTF8.GetString(bytes)); + } + } +} \ No newline at end of file From 43f5c80d4f1261e47f328d220f5c4f2883421189 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 4 Apr 2019 17:21:52 +0300 Subject: [PATCH 2/4] Configure authentication inside AbpAccountWebIdentityServerModule to properly set default schema. --- .../AbpAccountWebIdentityServerModule.cs | 22 ++++++++++++++++++- .../AbpAccountWebModule.cs | 2 -- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.cs index 6a68ebc91a..b7f1557ed9 100644 --- a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.cs +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.cs @@ -1,4 +1,7 @@ -using Volo.Abp.IdentityServer; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Identity.AspNetCore; +using Volo.Abp.IdentityServer; using Volo.Abp.Modularity; using Volo.Abp.VirtualFileSystem; @@ -10,12 +13,29 @@ namespace Volo.Abp.Account.Web )] public class AbpAccountWebIdentityServerModule : AbpModule { + public override void PreConfigureServices(ServiceConfigurationContext context) + { + context.Services.PreConfigure(options => + { + options.ConfigureAuthentication = false; + }); + } + public override void ConfigureServices(ServiceConfigurationContext context) { Configure(options => { options.FileSets.AddEmbedded("Volo.Abp.Account.Web"); }); + + //TODO: Try to reuse from AbpIdentityAspNetCoreModule + context.Services + .AddAuthentication(o => + { + o.DefaultScheme = IdentityConstants.ApplicationScheme; + o.DefaultSignInScheme = IdentityConstants.ExternalScheme; + }) + .AddIdentityCookies(); } } } diff --git a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs index e999cf1450..846c31763c 100644 --- a/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs +++ b/modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs @@ -1,7 +1,6 @@ using Localization.Resources.AbpUi; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Account.Web.Localization; -using Volo.Abp.Account.Web.Settings; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars; @@ -9,7 +8,6 @@ using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Localization; using Volo.Abp.Localization.Resources.AbpValidation; using Volo.Abp.Modularity; -using Volo.Abp.Settings; using Volo.Abp.UI.Navigation; using Volo.Abp.VirtualFileSystem; From 7267e7898e3f95ca3487b47ff26cd9703f5751be Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 4 Apr 2019 18:20:07 +0300 Subject: [PATCH 3/4] Resolved #962: Upgrade to Nito.AsyncEx libraries to 5.0 --- framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj b/framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj index e119d294cc..71d48038e2 100644 --- a/framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj +++ b/framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj @@ -24,7 +24,7 @@ - - + + \ No newline at end of file From 2f54aafc94496f6ea86e59cbeea5601a0b162b6f Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 4 Apr 2019 18:27:42 +0300 Subject: [PATCH 4/4] Use await RenderSectionAsync instead of RenderSection --- .../Themes/Basic/Layouts/Account.cshtml | 4 ++-- .../Themes/Basic/Layouts/Application.cshtml | 4 ++-- .../Themes/Basic/Layouts/Empty.cshtml | 4 ++-- .../Pages/_Layout.cshtml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Account.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Account.cshtml index 1a305434db..43c05559f9 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Account.cshtml +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Account.cshtml @@ -33,7 +33,7 @@ - @RenderSection("styles", false) + @await RenderSectionAsync("styles", false) @@ -71,7 +71,7 @@ - @RenderSection("scripts", false) + @await RenderSectionAsync("scripts", false) \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml index 30abd06404..4864f2dafe 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml @@ -23,7 +23,7 @@ - @RenderSection("styles", false) + @await RenderSectionAsync("styles", false) @@ -39,7 +39,7 @@ - @RenderSection("scripts", false) + @await RenderSectionAsync("scripts", false) \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml index c218f2a918..3b519fd223 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml @@ -22,7 +22,7 @@ - @RenderSection("styles", false) + @await RenderSectionAsync("styles", false) @@ -36,7 +36,7 @@ - @RenderSection("scripts", false) + @await RenderSectionAsync("scripts", false) \ No newline at end of file diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/_Layout.cshtml b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/_Layout.cshtml index c1fd7bd82b..9df9f9278f 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/_Layout.cshtml +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/_Layout.cshtml @@ -20,7 +20,7 @@ - @RenderSection("styles", false) + @await RenderSectionAsync("styles", false) @@ -30,7 +30,7 @@ - @RenderSection("scripts", false) + @await RenderSectionAsync("scripts", false) \ No newline at end of file