-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't configure JsonOptions by default (#16837)
Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
- Loading branch information
1 parent
8de0e71
commit 5770ac8
Showing
12 changed files
with
124 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
src/OrchardCore/OrchardCore.Abstractions/Json/JsonOptionsConfigurations.cs
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
src/OrchardCore/OrchardCore.Contents.Core/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using OrchardCore.Contents.Core.Services; | ||
|
||
namespace OrchardCore.Contents.Core; | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddContentServices(this IServiceCollection services) | ||
{ | ||
services.AddTransient<IConfigureOptions<MvcOptions>, MvcOptionsConfiguration>(); | ||
|
||
return services; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/OrchardCore/OrchardCore.Contents.Core/Services/ContentSystemTextJsonOutputFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Text.Json; | ||
using Microsoft.AspNetCore.Mvc.Formatters; | ||
using OrchardCore.ContentManagement; | ||
|
||
namespace OrchardCore.Contents.Core.Services; | ||
|
||
public sealed class ContentSystemTextJsonOutputFormatter : SystemTextJsonOutputFormatter | ||
{ | ||
public ContentSystemTextJsonOutputFormatter(JsonSerializerOptions jsonSerializerOptions) | ||
: base(jsonSerializerOptions) | ||
{ | ||
} | ||
|
||
protected override bool CanWriteType(Type type) | ||
=> typeof(IContent).IsAssignableFrom(type); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/OrchardCore/OrchardCore.Contents.Core/Services/MvcOptionsConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Options; | ||
using OrchardCore.Json; | ||
|
||
namespace OrchardCore.Contents.Core.Services; | ||
|
||
internal sealed class MvcOptionsConfiguration : IConfigureOptions<MvcOptions> | ||
{ | ||
private readonly DocumentJsonSerializerOptions _documentOptions; | ||
|
||
public MvcOptionsConfiguration(IOptions<DocumentJsonSerializerOptions> documentOptions) | ||
{ | ||
_documentOptions = documentOptions.Value; | ||
} | ||
|
||
public void Configure(MvcOptions options) | ||
{ | ||
options.OutputFormatters.Insert(0, new ContentSystemTextJsonOutputFormatter(_documentOptions.SerializerOptions)); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/OrchardCore/OrchardCore/Extensions/DocumentSystemTextJsonOutputFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Text.Json; | ||
using Microsoft.AspNetCore.Mvc.Formatters; | ||
using OrchardCore.Data.Documents; | ||
using OrchardCore.Entities; | ||
|
||
namespace OrchardCore.Json; | ||
|
||
public sealed class DocumentSystemTextJsonOutputFormatter : SystemTextJsonOutputFormatter | ||
{ | ||
public DocumentSystemTextJsonOutputFormatter(JsonSerializerOptions jsonSerializerOptions) | ||
: base(jsonSerializerOptions) | ||
{ | ||
} | ||
|
||
protected override bool CanWriteType(Type type) | ||
=> typeof(IDocument).IsAssignableFrom(type) || | ||
typeof(IEntity).IsAssignableFrom(type); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/OrchardCore/OrchardCore/Extensions/MvcOptionsConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Options; | ||
using OrchardCore.Json; | ||
|
||
namespace OrchardCore.Extensions; | ||
|
||
internal sealed class MvcOptionsConfiguration : IConfigureOptions<MvcOptions> | ||
{ | ||
private readonly DocumentJsonSerializerOptions _documentOptions; | ||
|
||
public MvcOptionsConfiguration(IOptions<DocumentJsonSerializerOptions> documentOptions) | ||
{ | ||
_documentOptions = documentOptions.Value; | ||
} | ||
|
||
public void Configure(MvcOptions options) | ||
{ | ||
options.OutputFormatters.Insert(0, new DocumentSystemTextJsonOutputFormatter(_documentOptions.SerializerOptions)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters