From 1960d5acfe7852bcaeee9154c9e76c91825d4176 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 15 Dec 2021 15:20:25 +0800 Subject: [PATCH] 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; } } }