Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Serializers #15633

Merged
merged 5 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AdminMenuDeploymentSource : IDeploymentSource
private readonly JsonSerializerOptions _serializationOptions;

public AdminMenuDeploymentSource(IAdminMenuService adminMenuService,
IOptions<ContentSerializerJsonOptions> serializationOptions)
IOptions<DocumentJsonSerializerOptions> serializationOptions)
{
_adminMenuService = adminMenuService;
_serializationOptions = serializationOptions.Value.SerializerOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AdminMenuStep : IRecipeStepHandler

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override void ConfigureServices(IServiceCollection services)
// Common types of converters are already configured in the assembly "GraphQL.SystemTextJson".
options.Converters.Add(GraphQLNamedQueryRequestJsonConverter.Instance);

var contentSerializerJsonOptions = sp.GetRequiredService<IOptions<ContentSerializerJsonOptions>>().Value;
var contentSerializerJsonOptions = sp.GetRequiredService<IOptions<DocumentJsonSerializerOptions>>().Value;
options.Merge(contentSerializerJsonOptions.SerializerOptions);
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DeploymentPlanDeploymentSource : IDeploymentSource
public DeploymentPlanDeploymentSource(
IDeploymentPlanService deploymentPlanService,
IEnumerable<IDeploymentStepFactory> deploymentStepFactories,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions)
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions)
{
_deploymentPlanService = deploymentPlanService;
_deploymentStepFactories = deploymentStepFactories;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DeploymentPlansRecipeStep : IRecipeStepHandler

public DeploymentPlansRecipeStep(
IServiceProvider serviceProvider,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions,
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions,
IDeploymentPlanService deploymentPlanService)
{
_serviceProvider = serviceProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AllLayersDeploymentSource : IDeploymentSource
public AllLayersDeploymentSource(
ILayerService layerService,
ISiteService siteService,
IOptions<ContentSerializerJsonOptions> serializationOptions)
IOptions<DocumentJsonSerializerOptions> serializationOptions)
{
_layerService = layerService;
_siteService = siteService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public LayerStep(
IRuleMigrator ruleMigrator,
IConditionIdGenerator conditionIdGenerator,
IEnumerable<IConditionFactory> factories,
IOptions<ContentSerializerJsonOptions> serializationOptions)
IOptions<DocumentJsonSerializerOptions> serializationOptions)
{
_layerService = layerService;
_ruleMigrator = ruleMigrator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PlacementsDeploymentSource : IDeploymentSource

public PlacementsDeploymentSource(
PlacementsManager placementsManager,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions)
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions)
{
_placementsManager = placementsManager;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AllQueriesDeploymentSource : IDeploymentSource

public AllQueriesDeploymentSource(
IQueryManager queryManager,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions)
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions)
{
_queryManager = queryManager;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class QueryStep : IRecipeStepHandler
public QueryStep(
IQueryManager queryManager,
IEnumerable<IQuerySource> querySources,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions,
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions,
ILogger<QueryStep> logger)
{
_queryManager = queryManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public SqlQuerySource(
ILiquidTemplateManager liquidTemplateManager,
IDbConnectionAccessor dbConnectionAccessor,
ISession session,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions,
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions,
IOptions<TemplateOptions> templateOptions)
{
_liquidTemplateManager = liquidTemplateManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AllWorkflowTypeDeploymentSource : IDeploymentSource

public AllWorkflowTypeDeploymentSource(
IWorkflowTypeStore workflowTypeStore,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions)
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions)
{
_workflowTypeStore = workflowTypeStore;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public WorkflowTypeStep(IWorkflowTypeStore workflowTypeStore,
ISecurityTokenService securityTokenService,
IActionContextAccessor actionContextAccessor,
IUrlHelperFactory urlHelperFactory,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions)
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions)
{
_workflowTypeStore = workflowTypeStore;
_securityTokenService = securityTokenService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public WorkflowManager
ILogger<WorkflowManager> logger,
ILogger<MissingActivity> missingActivityLogger,
IStringLocalizer<MissingActivity> missingActivityLocalizer,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions,
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions,
IClock clock)
{
_activityLibrary = activityLibrary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public UserTaskEventContentDriver(
IWorkflowManager workflowManager,
INotifier notifier,
IHtmlLocalizer<UserTaskEventContentDriver> localizer,
IOptions<ContentSerializerJsonOptions> jsonSerializerOptions,
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions,
IHttpContextAccessor httpContextAccessor)
{
_workflowStore = workflowStore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

namespace OrchardCore.Extensions;

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

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

public void Configure(ContentSerializerJsonOptions options)
public void Configure(DocumentJsonSerializerOptions options)
{
options.SerializerOptions.DefaultIgnoreCondition = JOptions.Base.DefaultIgnoreCondition;
options.SerializerOptions.ReferenceHandler = JOptions.Base.ReferenceHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace OrchardCore.Json;

public class ContentSerializerJsonOptions
public class DocumentJsonSerializerOptions
{
public JsonSerializerOptions SerializerOptions { get; } = new JsonSerializerOptions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text.Json.Serialization;

namespace OrchardCore.Json;

public class JsonDerivedTypesOptions
{
internal Dictionary<Type, List<IJsonDerivedTypeInfo>> DerivedTypes { get; } = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace OrchardCore.Json;

public class JsonOptionsConfigurations : IConfigureOptions<JsonOptions>
internal sealed class JsonOptionsConfigurations : IConfigureOptions<JsonOptions>
{
private readonly JsonSerializerOptions _jsonSerializerOptions;

public JsonOptionsConfigurations(IOptions<ContentSerializerJsonOptions> jsonSerializerOptions)
public JsonOptionsConfigurations(IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions)
{
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

namespace YesSql.Serialization
{
public class DefaultJsonContentSerializer : IContentSerializer
public class DefaultContentJsonSerializer : IContentSerializer
{
private readonly JsonSerializerOptions _options;

public DefaultJsonContentSerializer(IOptions<ContentSerializerJsonOptions> options)
public DefaultContentJsonSerializer(IOptions<DocumentJsonSerializerOptions> options)
{
_options = options.Value.SerializerOptions;
}

public DefaultJsonContentSerializer(JsonSerializerOptions options)
public DefaultContentJsonSerializer(JsonSerializerOptions options)
=> _options = options;

public object Deserialize(string content, Type type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private static YesSql.Configuration GetStoreConfiguration(IServiceProvider sp, Y
var tableNameFactory = sp.GetRequiredService<ITableNameConventionFactory>();
var loggerFactory = sp.GetRequiredService<ILoggerFactory>();

var serializerOptions = sp.GetRequiredService<IOptions<ContentSerializerJsonOptions>>();
var serializerOptions = sp.GetRequiredService<IOptions<DocumentJsonSerializerOptions>>();

var storeConfiguration = new YesSql.Configuration
{
Expand All @@ -189,7 +189,7 @@ private static YesSql.Configuration GetStoreConfiguration(IServiceProvider sp, Y
TableNameConvention = tableNameFactory.Create(databaseTableOptions),
IdentityColumnSize = Enum.Parse<IdentityColumnSize>(databaseTableOptions.IdentityColumnSize),
Logger = loggerFactory.CreateLogger("YesSql"),
ContentSerializer = new DefaultJsonContentSerializer(serializerOptions.Value.SerializerOptions)
ContentSerializer = new DefaultContentJsonSerializer(serializerOptions.Value.SerializerOptions)
};

if (yesSqlOptions.IdGenerator != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static IServiceCollection AddUsers(this IServiceCollection services)
services.AddScoped<ITwoFactorAuthenticationHandler, DefaultTwoFactorAuthenticationHandler>();
services.AddScoped<ITwoFactorAuthenticationHandlerCoordinator, DefaultTwoFactorAuthenticationHandlerCoordinator>();

services.Configure<ContentSerializerJsonOptions>(options =>
services.Configure<DocumentJsonSerializerOptions>(options =>
{
options.SerializerOptions.Converters.Add(new LoginInfoJsonConverter());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private static void AddDefaultServices(OrchardCoreBuilder builder)
services.AddSingleton<IPoweredByMiddlewareOptions, PoweredByMiddlewareOptions>();

services.AddTransient<IConfigureOptions<JsonOptions>, JsonOptionsConfigurations>();
services.AddTransient<IConfigureOptions<ContentSerializerJsonOptions>, ContentSerializerJsonOptionsConfiguration>();
services.AddTransient<IConfigureOptions<DocumentJsonSerializerOptions>, DocumentJsonSerializerOptionsConfiguration>();

services.AddScoped<IOrchardHelper, DefaultOrchardHelper>();
services.AddSingleton<IClientIPAddressAccessor, DefaultClientIPAddressAccessor>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public async Task InitializeAsync()
derivedOptions.Setup(x => x.Value)
.Returns(new JsonDerivedTypesOptions());

var configuration = new ContentSerializerJsonOptionsConfiguration(derivedOptions.Object);
var configuration = new DocumentJsonSerializerOptionsConfiguration(derivedOptions.Object);

var jsonOptions = new ContentSerializerJsonOptions();
var jsonOptions = new DocumentJsonSerializerOptions();
configuration.Configure(jsonOptions);

var jsonSerializerOptions = new Mock<IOptions<ContentSerializerJsonOptions>>();
var jsonSerializerOptions = new Mock<IOptions<DocumentJsonSerializerOptions>>();
jsonSerializerOptions.Setup(x => x.Value)
.Returns(jsonOptions);

var contentSerializer = new DefaultJsonContentSerializer(jsonSerializerOptions.Object);
var contentSerializer = new DefaultContentJsonSerializer(jsonSerializerOptions.Object);

_store.Configuration.ContentSerializer = contentSerializer;
_prefixedStore.Configuration.ContentSerializer = contentSerializer;
Expand Down
4 changes: 2 additions & 2 deletions test/OrchardCore.Tests/Workflows/WorkflowManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ WorkflowType workflowType
var missingActivityLocalizer = new Mock<IStringLocalizer<MissingActivity>>();
var clock = new Mock<IClock>();
var workflowFaultHandler = new Mock<IWorkflowFaultHandler>();
var jsonOptionsMock = new Mock<IOptions<ContentSerializerJsonOptions>>();
var jsonOptionsMock = new Mock<IOptions<DocumentJsonSerializerOptions>>();
jsonOptionsMock.Setup(x => x.Value)
.Returns(new ContentSerializerJsonOptions());
.Returns(new DocumentJsonSerializerOptions());

var workflowManager = new WorkflowManager(
activityLibrary.Object,
Expand Down
Loading