Open
Description
Show example with new hosting model for
https://docs.microsoft.com/en-us/aspnet/core/web-api/jsonpatch?view=aspnetcore-6.0#json-patch-addnewtonsoftjson-and-systemtextjson
The current implementation results in warning
Warning ASP0000 Calling 'BuildServiceProvider' from application code results in an additional copy of singleton services being created. Consider alternatives such as dependency injecting services as parameters to 'Configure'.
This is relevant to code
static NewtonsoftJsonPatchInputFormatter GetJsonPatchInputFormatter()
{
var builder = new ServiceCollection()
.AddLogging()
.AddMvc()
.AddNewtonsoftJson()
.Services.BuildServiceProvider();
return builder
.GetRequiredService<IOptions<MvcOptions>>()
.Value
.InputFormatters
.OfType<NewtonsoftJsonPatchInputFormatter>()
.First();
}
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 20acee3e-8b6e-b3fb-8271-661e1a287bdd
- Version Independent ID: 20acee3e-8b6e-b3fb-8271-661e1a287bdd
- Content: Code samples migrated from ASP.NET Core 5.0 to 6.0
- Content Source: aspnetcore/migration/50-to-60-samples.md
- Product: aspnet-core
- Technology: aspnetcore-migration
- GitHub Login: @Rick-Anderson
- Microsoft Alias: riande