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..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 @@ -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 IMvcCoreBuilder 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 8a83c93a85..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 @@ -119,7 +119,6 @@ namespace Volo.Abp.AspNetCore.Mvc ); var mvcBuilder = context.Services.AddMvc() - .AddRazorRuntimeCompilation() .AddDataAnnotationsLocalization(options => { options.DataAnnotationLocalizerProvider = (type, factory) => @@ -139,16 +138,13 @@ 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. - mvcCoreBuilder.AddAbpHybridJson(); - - Configure(options => + if (context.Services.GetHostingEnvironment().IsDevelopment() && + context.Services.ExecutePreConfiguredActions().EnableRazorRuntimeCompilationOnDevelopment) { - options.FileProviders.Add( - new RazorViewEngineVirtualFileProvider( - context.Services.GetSingletonInstance>() - ) - ); - }); + 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; } } } 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);