dotnet / dotnet/AspNetCore.Docs
Provide updated JsonPatch sample for new hosting model
- Dominant language
- C#
- Stars
- 13.1k
- Forks
- 24.6k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 97
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>()
.Value
.InputFormatters
.OfType()
.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](https://docs.microsoft.com/en-us/aspnet/core/migration/50-to-60-samples?view=aspnetcore-5.0)
* Content Source: [aspnetcore/migration/50-to-60-samples.md](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/migration/50-to-60-samples.md)
* Product: **aspnet-core**
* Technology: **aspnetcore-migration**
* GitHub Login: @Rick-Anderson
* Microsoft Alias: **riande**
Contributor guide
Assessment
This issue has not been assessed yet.