Skip to content

Commit

Permalink
Use ContentSerializerJsonOptions to configure content-serializer (Orc…
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored and urbanit committed Mar 18, 2024
1 parent c00116b commit 1a0cd2f
Show file tree
Hide file tree
Showing 24 changed files with 106 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Extensions.Options;
using OrchardCore.AdminMenu.Services;
using OrchardCore.Deployment;
using OrchardCore.Json;

namespace OrchardCore.AdminMenu.Deployment
{
Expand All @@ -12,10 +13,11 @@ public class AdminMenuDeploymentSource : IDeploymentSource
private readonly IAdminMenuService _adminMenuService;
private readonly JsonSerializerOptions _serializationOptions;

public AdminMenuDeploymentSource(IAdminMenuService adminMenuService, IOptions<JsonSerializerOptions> serializationOptions)
public AdminMenuDeploymentSource(IAdminMenuService adminMenuService,
IOptions<ContentSerializerJsonOptions> serializationOptions)
{
_adminMenuService = adminMenuService;
_serializationOptions = serializationOptions.Value;
_serializationOptions = serializationOptions.Value.SerializerOptions;
}

public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using OrchardCore.AdminMenu.Services;
using OrchardCore.Json;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;

Expand All @@ -20,12 +21,12 @@ public class AdminMenuStep : IRecipeStepHandler

public AdminMenuStep(
IAdminMenuService adminMenuService,
IOptions<JsonSerializerOptions> serializationOptions)
IOptions<ContentSerializerJsonOptions> serializationOptions)
{
_adminMenuService = adminMenuService;

// The recipe step contains polymorphic types (menu items) which need to be resolved
_serializationOptions = serializationOptions.Value;
_serializationOptions = serializationOptions.Value.SerializerOptions;
}

public async Task ExecuteAsync(RecipeExecutionContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using OrchardCore.Json;

namespace OrchardCore.Deployment.Deployment
{
Expand All @@ -16,11 +17,11 @@ public class DeploymentPlanDeploymentSource : IDeploymentSource
public DeploymentPlanDeploymentSource(
IDeploymentPlanService deploymentPlanService,
IEnumerable<IDeploymentStepFactory> deploymentStepFactories,
IOptions<JsonSerializerOptions> jsonSerializerOptions)
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions)
{
_deploymentPlanService = deploymentPlanService;
_deploymentStepFactories = deploymentStepFactories;
_jsonSerializerOptions = jsonSerializerOptions.Value;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
}

public async Task ProcessDeploymentStepAsync(DeploymentStep deploymentStep, DeploymentPlanResult result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OrchardCore.Json;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;

Expand All @@ -22,11 +23,11 @@ public class DeploymentPlansRecipeStep : IRecipeStepHandler

public DeploymentPlansRecipeStep(
IServiceProvider serviceProvider,
IOptions<JsonSerializerOptions> jsonSerializerOptions,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions,
IDeploymentPlanService deploymentPlanService)
{
_serviceProvider = serviceProvider;
_jsonSerializerOptions = jsonSerializerOptions.Value;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
_deploymentPlanService = deploymentPlanService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using OrchardCore.Deployment;
using OrchardCore.Json;
using OrchardCore.Layers.Models;
using OrchardCore.Layers.Services;
using OrchardCore.Settings;
Expand All @@ -18,11 +19,11 @@ public class AllLayersDeploymentSource : IDeploymentSource
public AllLayersDeploymentSource(
ILayerService layerService,
ISiteService siteService,
IOptions<JsonSerializerOptions> serializationOptions)
IOptions<ContentSerializerJsonOptions> serializationOptions)
{
_layerService = layerService;
_siteService = siteService;
_jsonSerializerOptions = serializationOptions.Value;
_jsonSerializerOptions = serializationOptions.Value.SerializerOptions;
}

public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using OrchardCore.Json;
using OrchardCore.Layers.Models;
using OrchardCore.Layers.Services;
using OrchardCore.Recipes.Models;
Expand All @@ -30,13 +31,13 @@ public LayerStep(
IRuleMigrator ruleMigrator,
IConditionIdGenerator conditionIdGenerator,
IEnumerable<IConditionFactory> factories,
IOptions<JsonSerializerOptions> serializationOptions)
IOptions<ContentSerializerJsonOptions> serializationOptions)
{
_layerService = layerService;
_ruleMigrator = ruleMigrator;
_conditionIdGenerator = conditionIdGenerator;
_factories = factories;
_serializationOptions = serializationOptions.Value;
_serializationOptions = serializationOptions.Value.SerializerOptions;
}

public async Task ExecuteAsync(RecipeExecutionContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using OrchardCore.Deployment;
using OrchardCore.Json;
using OrchardCore.Placements.Services;

namespace OrchardCore.Placements.Deployment
Expand All @@ -14,10 +15,10 @@ public class PlacementsDeploymentSource : IDeploymentSource

public PlacementsDeploymentSource(
PlacementsManager placementsManager,
IOptions<JsonSerializerOptions> jsonSerializerOptions)
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions)
{
_placementsManager = placementsManager;
_jsonSerializerOptions = jsonSerializerOptions.Value;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
}

public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using OrchardCore.Deployment;
using OrchardCore.Json;

namespace OrchardCore.Queries.Deployment
{
Expand All @@ -13,10 +14,10 @@ public class AllQueriesDeploymentSource : IDeploymentSource

public AllQueriesDeploymentSource(
IQueryManager queryManager,
IOptions<JsonSerializerOptions> jsonSerializerOptions)
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions)
{
_queryManager = queryManager;
_jsonSerializerOptions = jsonSerializerOptions.Value;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
}

public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OrchardCore.Json;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;

Expand All @@ -24,12 +25,12 @@ public class QueryStep : IRecipeStepHandler
public QueryStep(
IQueryManager queryManager,
IEnumerable<IQuerySource> querySources,
IOptions<JsonSerializerOptions> jsonSerializerOptions,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions,
ILogger<QueryStep> logger)
{
_queryManager = queryManager;
_querySources = querySources;
_jsonSerializerOptions = jsonSerializerOptions.Value;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
_logger = logger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Extensions.Options;
using OrchardCore.ContentManagement;
using OrchardCore.Data;
using OrchardCore.Json;
using OrchardCore.Liquid;
using YesSql;

Expand All @@ -27,13 +28,13 @@ public SqlQuerySource(
ILiquidTemplateManager liquidTemplateManager,
IDbConnectionAccessor dbConnectionAccessor,
ISession session,
IOptions<JsonSerializerOptions> jsonSerializerOptions,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions,
IOptions<TemplateOptions> templateOptions)
{
_liquidTemplateManager = liquidTemplateManager;
_dbConnectionAccessor = dbConnectionAccessor;
_session = session;
_jsonSerializerOptions = jsonSerializerOptions.Value;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
_templateOptions = templateOptions.Value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using OrchardCore.Deployment;
using OrchardCore.Json;
using OrchardCore.Workflows.Services;

namespace OrchardCore.Workflows.Deployment
Expand All @@ -14,10 +15,10 @@ public class AllWorkflowTypeDeploymentSource : IDeploymentSource

public AllWorkflowTypeDeploymentSource(
IWorkflowTypeStore workflowTypeStore,
IOptions<JsonSerializerOptions> jsonSerializerOptions)
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions)
{
_workflowTypeStore = workflowTypeStore;
_jsonSerializerOptions = jsonSerializerOptions.Value;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
}

public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.Extensions.Options;
using OrchardCore.Json;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;
using OrchardCore.Workflows.Http.Activities;
Expand All @@ -29,13 +30,13 @@ public WorkflowTypeStep(IWorkflowTypeStore workflowTypeStore,
ISecurityTokenService securityTokenService,
IActionContextAccessor actionContextAccessor,
IUrlHelperFactory urlHelperFactory,
IOptions<JsonSerializerOptions> jsonSerializerOptions)
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions)
{
_workflowTypeStore = workflowTypeStore;
_securityTokenService = securityTokenService;
_actionContextAccessor = actionContextAccessor;
_urlHelperFactory = urlHelperFactory;
_jsonSerializerOptions = jsonSerializerOptions.Value;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
}

public async Task ExecuteAsync(RecipeExecutionContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OrchardCore.Json;
using OrchardCore.Locking.Distributed;
using OrchardCore.Modules;
using OrchardCore.Workflows.Activities;
Expand Down Expand Up @@ -50,7 +51,7 @@ public WorkflowManager
ILogger<WorkflowManager> logger,
ILogger<MissingActivity> missingActivityLogger,
IStringLocalizer<MissingActivity> missingActivityLocalizer,
IOptions<JsonSerializerOptions> jsonSerializerOptions,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions,
IClock clock)
{
_activityLibrary = activityLibrary;
Expand All @@ -63,7 +64,7 @@ public WorkflowManager
_logger = logger;
_missingActivityLogger = missingActivityLogger;
_missingActivityLocalizer = missingActivityLocalizer;
_jsonSerializerOptions = jsonSerializerOptions.Value;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
_clock = clock;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Notify;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Json;
using OrchardCore.Workflows.Models;
using OrchardCore.Workflows.Services;
using OrchardCore.Workflows.UserTasks.Activities;
Expand All @@ -38,15 +39,15 @@ public UserTaskEventContentDriver(
IWorkflowManager workflowManager,
INotifier notifier,
IHtmlLocalizer<UserTaskEventContentDriver> localizer,
IOptions<JsonSerializerOptions> jsonSerializerOptions,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions,
IHttpContextAccessor httpContextAccessor)
{
_workflowStore = workflowStore;
_activityLibrary = activityLibrary;
_workflowManager = workflowManager;
_notifier = notifier;
_httpContextAccessor = httpContextAccessor;
_jsonSerializerOptions = jsonSerializerOptions.Value;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;

H = localizer;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Options;
using OrchardCore.Json;
using OrchardCore.Json.Serialization;

namespace OrchardCore.Extensions;

public class ContentSerializerJsonOptionsConfiguration : IConfigureOptions<ContentSerializerJsonOptions>
{
private readonly JsonDerivedTypesOptions _derivedTypesOptions;

public ContentSerializerJsonOptionsConfiguration(IOptions<JsonDerivedTypesOptions> derivedTypesOptions)
{
_derivedTypesOptions = derivedTypesOptions.Value;
}

public void Configure(ContentSerializerJsonOptions options)
{
options.SerializerOptions.DefaultIgnoreCondition = JOptions.Base.DefaultIgnoreCondition;
options.SerializerOptions.ReferenceHandler = JOptions.Base.ReferenceHandler;
options.SerializerOptions.ReadCommentHandling = JOptions.Base.ReadCommentHandling;
options.SerializerOptions.PropertyNameCaseInsensitive = JOptions.Base.PropertyNameCaseInsensitive;
options.SerializerOptions.AllowTrailingCommas = JOptions.Base.AllowTrailingCommas;
options.SerializerOptions.WriteIndented = JOptions.Base.WriteIndented;

options.SerializerOptions.TypeInfoResolverChain.Add(new PolymorphicJsonTypeInfoResolver(_derivedTypesOptions));
options.SerializerOptions.Converters.Add(DynamicJsonConverter.Instance);
options.SerializerOptions.Converters.Add(PathStringJsonConverter.Instance);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Text.Json;

namespace OrchardCore.Json;

public class ContentSerializerJsonOptions
{
public JsonSerializerOptions SerializerOptions { get; } = new JsonSerializerOptions();
}
Loading

0 comments on commit 1a0cd2f

Please sign in to comment.