From 136e70e0340ff4e99bbea90d00f2b2ef03d3d617 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 15 Dec 2021 12:34:38 +0800 Subject: [PATCH 1/3] No longer use `AddRazorRuntimeCompilation`. --- .../Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index 8a83c93a85..cbc81f352b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -119,7 +119,6 @@ namespace Volo.Abp.AspNetCore.Mvc ); var mvcBuilder = context.Services.AddMvc() - .AddRazorRuntimeCompilation() .AddDataAnnotationsLocalization(options => { options.DataAnnotationLocalizerProvider = (type, factory) => From 6596d9776a633bbd93d2204501c3b4bf43147e43 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 15 Dec 2021 14:40:21 +0800 Subject: [PATCH 2/3] Fix unit tests. --- .../AbpMvcBuilderExtensions.cs | 23 ++++++++++++-- .../AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs | 9 ------ .../Volo.Abp.AspNetCore.Mvc.Tests.csproj | 30 ------------------- .../Mvc/AbpAspNetCoreMvcTestModule.cs | 6 ++++ 4 files changed, 26 insertions(+), 42 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs index c7f3777466..48e4f2716f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs @@ -1,7 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation; +using Volo.Abp.AspNetCore.VirtualFileSystem; +using Volo.Abp.DependencyInjection; namespace Microsoft.Extensions.DependencyInjection { @@ -11,12 +15,12 @@ namespace Microsoft.Extensions.DependencyInjection { mvcBuilder.PartManager.ApplicationParts.AddIfNotContains(assembly); } - + public static void AddApplicationPartIfNotExists(this IMvcCoreBuilder mvcCoreBuilder, Assembly assembly) { mvcCoreBuilder.PartManager.ApplicationParts.AddIfNotContains(assembly); } - + public static void AddIfNotContains(this IList applicationParts, Assembly assembly) { if (applicationParts.Any( @@ -27,5 +31,18 @@ namespace Microsoft.Extensions.DependencyInjection applicationParts.Add(new AssemblyPart(assembly)); } + + public static void AddAbpRazorRuntimeCompilation(this IMvcBuilder mvcCoreBuilder) + { + mvcCoreBuilder.AddRazorRuntimeCompilation(); + mvcCoreBuilder.Services.Configure(options => + { + options.FileProviders.Add( + new RazorViewEngineVirtualFileProvider( + mvcCoreBuilder.Services.GetSingletonInstance>() + ) + ); + }); + } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index cbc81f352b..b08406fcf0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -140,15 +140,6 @@ namespace Volo.Abp.AspNetCore.Mvc mvcCoreBuilder.AddAbpHybridJson(); - Configure(options => - { - options.FileProviders.Add( - new RazorViewEngineVirtualFileProvider( - context.Services.GetSingletonInstance>() - ) - ); - }); - context.Services.ExecutePreConfiguredActions(mvcBuilder); //TODO: AddViewLocalization by default..? diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj index 3a923ba799..4e1b5e1334 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj @@ -40,36 +40,6 @@ PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs index 0b84b00f7d..2c8ba3d8d1 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Security.Claims; using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AspNetCore.Mvc.Authorization; @@ -115,6 +116,11 @@ namespace Volo.Abp.AspNetCore.Mvc options.RootDirectory = "/Volo/Abp/AspNetCore/Mvc"; }); + Configure(options => + { + options.ViewLocationFormats.Add("/Volo/Abp/AspNetCore/App/Views/{1}/{0}.cshtml"); + }); + Configure(options => { options.Maps.Add("SerialNumber", () => ClaimTypes.SerialNumber); From 1960d5acfe7852bcaeee9154c9e76c91825d4176 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 15 Dec 2021 15:20:25 +0800 Subject: [PATCH 3/3] Add `EnableRazorRuntimeCompilationOnDevelopment` --- .../DependencyInjection/AbpMvcBuilderExtensions.cs | 2 +- .../Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs | 6 ++++++ .../Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs index 48e4f2716f..0f4912d105 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpMvcBuilderExtensions.cs @@ -32,7 +32,7 @@ namespace Microsoft.Extensions.DependencyInjection applicationParts.Add(new AssemblyPart(assembly)); } - public static void AddAbpRazorRuntimeCompilation(this IMvcBuilder mvcCoreBuilder) + public static void AddAbpRazorRuntimeCompilation(this IMvcCoreBuilder mvcCoreBuilder) { mvcCoreBuilder.AddRazorRuntimeCompilation(); mvcCoreBuilder.Services.Configure(options => diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index b08406fcf0..a9090d3a48 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -138,6 +138,12 @@ namespace Volo.Abp.AspNetCore.Mvc }) .AddViewLocalization(); //TODO: How to configure from the application? Also, consider to move to a UI module since APIs does not care about it. + if (context.Services.GetHostingEnvironment().IsDevelopment() && + context.Services.ExecutePreConfiguredActions().EnableRazorRuntimeCompilationOnDevelopment) + { + mvcCoreBuilder.AddAbpRazorRuntimeCompilation(); + } + mvcCoreBuilder.AddAbpHybridJson(); context.Services.ExecutePreConfiguredActions(mvcBuilder); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs index 1378da8876..6993098b25 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs @@ -14,11 +14,14 @@ namespace Volo.Abp.AspNetCore.Mvc public bool AutoModelValidation { get; set; } + public bool EnableRazorRuntimeCompilationOnDevelopment { get; set; } + public AbpAspNetCoreMvcOptions() { ConventionalControllers = new AbpConventionalControllerOptions(); IgnoredControllersOnModelExclusion = new HashSet(); AutoModelValidation = true; + EnableRazorRuntimeCompilationOnDevelopment = true; } } }