From f1265ec3dfd9803b258d05babfb259b400c691f1 Mon Sep 17 00:00:00 2001 From: David Barker Date: Fri, 24 Jan 2020 10:32:54 +0800 Subject: [PATCH] add razor runtime compilation for development environment --- sample/MongoIdentitySample.Mvc/Startup.cs | 14 +++++++++++++- .../Views/Shared/_Layout.cshtml | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sample/MongoIdentitySample.Mvc/Startup.cs b/sample/MongoIdentitySample.Mvc/Startup.cs index 48cbab4..cbf26a8 100644 --- a/sample/MongoIdentitySample.Mvc/Startup.cs +++ b/sample/MongoIdentitySample.Mvc/Startup.cs @@ -15,8 +15,10 @@ namespace MongoIdentitySample.Mvc { public class Startup { + private IWebHostEnvironment _env; public Startup(IWebHostEnvironment env) { + _env = env; var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) @@ -38,12 +40,22 @@ namespace MongoIdentitySample.Mvc var settings = Configuration.GetSection(nameof(MongoDbSettings)).Get(); services.AddSingleton(settings); - + services.AddIdentity() .AddMongoDbStores(settings.ConnectionString, settings.DatabaseName) .AddSignInManager() .AddDefaultTokenProviders(); + + var builder = services.AddRazorPages(); + + #if DEBUG + if(_env.IsDevelopment()) + { + builder.AddRazorRuntimeCompilation(); + } + #endif + services.AddMvc(); services.AddApplicationInsightsTelemetry(); diff --git a/sample/MongoIdentitySample.Mvc/Views/Shared/_Layout.cshtml b/sample/MongoIdentitySample.Mvc/Views/Shared/_Layout.cshtml index 15c0be6..8cbfd77 100644 --- a/sample/MongoIdentitySample.Mvc/Views/Shared/_Layout.cshtml +++ b/sample/MongoIdentitySample.Mvc/Views/Shared/_Layout.cshtml @@ -31,7 +31,7 @@ @RenderBody()