WebApi + ClientApp, GraphQL, Reflection
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Events.WebAPI.Util.Extensions;
|
||||
|
||||
public static class AddJsonPatchSupportExtension
|
||||
{
|
||||
public static void AddJsonPatchSupport(this MvcOptions options)
|
||||
{
|
||||
options.InputFormatters.Insert(0, GetJsonPatchInputFormatter());
|
||||
}
|
||||
|
||||
// Add Newtonsoft only to the JSON Patch formatter so the rest of the API keeps System.Text.Json.
|
||||
private static NewtonsoftJsonPatchInputFormatter GetJsonPatchInputFormatter()
|
||||
{
|
||||
var builder = new ServiceCollection()
|
||||
.AddLogging()
|
||||
.AddControllers()
|
||||
.AddNewtonsoftJson()
|
||||
.Services
|
||||
.BuildServiceProvider();
|
||||
|
||||
return builder
|
||||
.GetRequiredService<IOptions<MvcOptions>>()
|
||||
.Value
|
||||
.InputFormatters
|
||||
.OfType<NewtonsoftJsonPatchInputFormatter>()
|
||||
.First();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user