From f75594feeab7d86d4f4862f1558ba8e1a2131f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Akan=20Edling?= Date: Tue, 15 Dec 2020 16:28:50 +0100 Subject: [PATCH] Added support for custom JSON settings. Fixes #1354 --- core/Piranha.Manager/ManagerExtensions.cs | 9 ++++++++- core/Piranha.Manager/ManagerStartupExtensions.cs | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/Piranha.Manager/ManagerExtensions.cs b/core/Piranha.Manager/ManagerExtensions.cs index 9dfc2e8dd..c105d6d8a 100644 --- a/core/Piranha.Manager/ManagerExtensions.cs +++ b/core/Piranha.Manager/ManagerExtensions.cs @@ -8,7 +8,9 @@ * */ +using System; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; @@ -301,7 +303,8 @@ public static void MapPiranhaManager(this IEndpointRouteBuilder builder) builder.MapRazorPages(); } - public static IMvcBuilder AddPiranhaManagerOptions(this IMvcBuilder builder) + public static IMvcBuilder AddPiranhaManagerOptions(this IMvcBuilder builder, + Action jsonOptions = null) { return builder .AddRazorPagesOptions(options => @@ -313,6 +316,10 @@ public static IMvcBuilder AddPiranhaManagerOptions(this IMvcBuilder builder) .AddDataAnnotationsLocalization() .AddNewtonsoftJson(options => { + // Invoke custom json options + jsonOptions?.Invoke(options); + + // Set required options for Piranha options.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto; }); } diff --git a/core/Piranha.Manager/ManagerStartupExtensions.cs b/core/Piranha.Manager/ManagerStartupExtensions.cs index 013c6c4f6..37739a00b 100644 --- a/core/Piranha.Manager/ManagerStartupExtensions.cs +++ b/core/Piranha.Manager/ManagerStartupExtensions.cs @@ -8,7 +8,9 @@ * */ +using System; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Piranha; using Piranha.AspNetCore; @@ -19,8 +21,10 @@ public static class ManagerStartupExtensions /// Uses the Piranha Manager services if simple startup is used. /// /// The service builder + /// Optional JSON options /// The updated builder - public static PiranhaServiceBuilder UseManager(this PiranhaServiceBuilder serviceBuilder) + public static PiranhaServiceBuilder UseManager(this PiranhaServiceBuilder serviceBuilder, + Action jsonOptions = null) { // Add dependent services serviceBuilder.Services.AddLocalization(options => @@ -28,7 +32,7 @@ public static PiranhaServiceBuilder UseManager(this PiranhaServiceBuilder servic ); serviceBuilder.Services.AddControllersWithViews(); serviceBuilder.Services.AddRazorPages() - .AddPiranhaManagerOptions(); + .AddPiranhaManagerOptions(jsonOptions); // Add manager services serviceBuilder.Services.AddPiranhaManager();