WebApi + ClientApp, GraphQL, Reflection

This commit is contained in:
Boris Milašinović
2026-05-06 20:55:05 +02:00
parent 8f7c704a90
commit 4fb3de19f6
196 changed files with 10395 additions and 0 deletions

View File

@@ -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();
}
}