Reputation: 729
I have a Net Core 2.2 Web Api that I protect with the integration of IdentityServer4. So I started from the tutorial of IDS4 to write the code and there I found the AddJsonFormatters().
I'm triyng to migrate it from .NET Core 2.2 to .NET Core 3.0.
At the moment I have a problem at compile time in the ConfigureServices().
I don't find the AddJsonFormatters() and if I correctly understand, I have to use the AddMvcOptions() to get the same result.
Is this correct? In this case, what is the equivalent configuration?
// .NET Core 2.2
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddAuthorization()
.AddJsonFormatters();
// Other code...
}
// .NET Core 3.0
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddAuthorization()
// Something like this...
.AddMvcOptions(options =>
{
//options.OutputFormatters.Add(new SomeKindOf_IOutputFormatter());
//options.InputFormatters.Add(new SomeKindOf_IInputFormatter(options));
});
// Other code...
}
Upvotes: 14
Views: 11074
Reputation: 101
You can use Microsoft.AspNetCore.Mvc.NewtonsoftJson NuGet package, and configure it in the Startup.cs:
services.AddMvcCore()
.AddNewtonsoftJson(o =>
{
o.SerializerSettings.Converters.Add(new StringEnumConverter());
o.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
})
Upvotes: 10
Reputation:
I just found out that IdentityServer4 are slowly updating their samples for .NET Core 3.0. Attached is the link to their newer version of the code for the part you are asking about, hope it helps. https://github.com/IdentityServer/IdentityServer4/blob/master/samples/Quickstarts/1_ClientCredentials/src/Api/Startup.cs
Upvotes: 6