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

Register JsonSerializerOptions in the IoC Container #15328

Merged
merged 15 commits into from
Feb 21, 2024
Merged

Register JsonSerializerOptions in the IoC Container #15328

merged 15 commits into from
Feb 21, 2024

Conversation

MikeAlhayek
Copy link
Member

@MikeAlhayek MikeAlhayek commented Feb 14, 2024

Registered a default JsonSerializerOptions
Lastly used the default JsonSerializerOptions when using JObject.FromObject.

@sebastienros
Copy link
Member

Just JsonSerializerOptions without the IOptions and without the IJsonSerializerOptions. I haven't check the code in detail but I don't think it's useful in our case. c.f. HtmlEncoder.

@MikeAlhayek
Copy link
Member Author

Why not use Options pattern? It maybe useful as some may way to configure the default setting differently.

@@ -152,6 +155,9 @@ private static void AddDefaultServices(OrchardCoreBuilder builder)

services.AddSingleton<IPoweredByMiddlewareOptions, PoweredByMiddlewareOptions>();

services.AddTransient<IConfigureOptions<JsonSerializerOptions>, JsonSerializerOptionsConfiguration>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we also register:

services.AddTransient<JsonSerializerOptions>(sp => sp.GetRequiredService<IOptions<JsonSerializerOptions>>().Value);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you get any feedback on this approach?

@MikeAlhayek MikeAlhayek requested a review from jtkech as a code owner February 16, 2024 17:40
@MikeAlhayek
Copy link
Member Author

@sebastienros I addressed your feedback. I also used IOptions<JsonSerializerOptions> all over the place. Note some extensions have breaking change. The breaking change will be a compile time error. Please do one more round of review here to make sure I did not miss something

@MikeAlhayek MikeAlhayek changed the title Add IJsonSerializer and register JsonSerializerOptions Register JsonSerializerOptions in the IoC Container Feb 16, 2024
Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

…izerOptionsConfiguration.cs

Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
Copy link
Member

@sebastienros sebastienros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a lot of changes are about ContentItem and I think this is not required. The test would be simple, put a "$type" property with something random and you'll see that the resulting content item will still have this property in it's Data property. That will only be the responsibility of the Part deserialization to use the options.

@MikeAlhayek
Copy link
Member Author

@sebastienros I made some more changes. There are multiple unrelated changes that you could just ignore. Let me know if you see anything else.

@hishamco
Copy link
Member

@MikeAlhayek what's the remaining in this PR, coz I requested changes in the past and I need to approve it, can I did second round review if it's complete

@MikeAlhayek
Copy link
Member Author

@hishamco it is complete. I know there are lots of unrelated changes here which is due to the files that were originally touched. I am waiting on @sebastienros to see if we got everything or not. I am not quite sure if the workflow state needs the serializer options here or not. But feel free to review it

@sebastienros
Copy link
Member

GTG

@MikeAlhayek
Copy link
Member Author

GTG

?

@sebastienros
Copy link
Member

Good To Go

@MikeAlhayek
Copy link
Member Author

MikeAlhayek commented Feb 21, 2024

Do you agree that WorkflowState needs the options?

@MikeAlhayek MikeAlhayek reopened this Feb 21, 2024
@MikeAlhayek MikeAlhayek merged commit a92ebbf into main Feb 21, 2024
7 checks passed
@MikeAlhayek MikeAlhayek deleted the ma/json branch February 21, 2024 20:50
urbanit pushed a commit to urbanit/OrchardCore that referenced this pull request Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants