summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2022-11-22 16:46:29 -0600
committerHombreLaser <sebastian-440@live.com>2022-11-22 16:46:29 -0600
commitea20e100d4afe4429ab4c24926bffc0a8f9b9b70 (patch)
tree413ba66d90d4bc0ec51e20abe73fc3b2d08f50d5
parentb3deb8c5d92dd616042ea9e265c197abe02f995c (diff)
Añadido configuración de newtonsoft json
-rw-r--r--JPIF.cs22
-rw-r--r--Program.cs9
2 files changed, 28 insertions, 3 deletions
diff --git a/JPIF.cs b/JPIF.cs
new file mode 100644
index 0000000..357c6d7
--- /dev/null
+++ b/JPIF.cs
@@ -0,0 +1,22 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Formatters;
+using Microsoft.Extensions.Options;
+
+namespace BackendPIA {
+ public static class JPIF {
+ public static NewtonsoftJsonPatchInputFormatter GetJsonPatchInputFormatter() {
+ var builder = new ServiceCollection()
+ .AddLogging()
+ .AddMvc()
+ .AddNewtonsoftJson()
+ .Services.BuildServiceProvider();
+
+ return builder
+ .GetRequiredService<IOptions<MvcOptions>>()
+ .Value
+ .InputFormatters
+ .OfType<NewtonsoftJsonPatchInputFormatter>()
+ .First();
+ }
+ }
+} \ No newline at end of file
diff --git a/Program.cs b/Program.cs
index 69244aa..38c1b4b 100644
--- a/Program.cs
+++ b/Program.cs
@@ -2,10 +2,11 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
-using System.IdentityModel.Tokens.Jwt;
-using System.Text.Json.Serialization;
+ // using System.IdentityModel.Tokens.Jwt;
+ // using System.Text.Json.Serialization;
using System.Text;
using Microsoft.EntityFrameworkCore;
+using BackendPIA;
using BackendPIA.Models;
using BackendPIA.Services;
@@ -13,7 +14,9 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
-builder.Services.AddControllers().AddNewtonsoftJson();
+builder.Services.AddControllers(options => {
+ options.InputFormatters.Insert(0, JPIF.GetJsonPatchInputFormatter());
+ }).AddNewtonsoftJson();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<ApplicationDbContext>(opt => opt.UseNpgsql(builder.Configuration.GetConnectionString("ApplicationDbContext")));