将ArrayPool对象提供给JsonOutputFormatter构造函数
从.net RC2升级到RTM后,我发现需要为从ArrayPool派生的JsonOutputFormatter的构造函数提供参数。 我如何获得此对象? 我正在手动创建JsonOutputFormatter,因为我需要配置ReferenceLoopHandling。
我能找到的其他相关信息是这样的: https : //github.com/aspnet/Mvc/issues/4562
public IServiceProvider ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMemoryCache(); services.AddSession(); services.AddMvc(); var formatterSettings = JsonSerializerSettingsProvider.CreateSerializerSettings(); formatterSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; JsonOutputFormatter formatter = new JsonOutputFormatter(formatterSettings, ???); services.Configure(options => { options.OutputFormatters.RemoveType(); options.OutputFormatters.Insert(0, formatter); }); //etc... }
var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool.Shared);
资源
在评论中:
JsonOutputFormatter在创建时需要ArrayPool,您可以传入ArrayPool.Shared。
我还注意到ArrayPool上有一个.Create()方法。
var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool.Create());
- 如何获得AssemblyTitle?
- 如何在.Net Core中不使用第三方记录器的情况下登录文件?
- 将私钥/公钥从X509证书导出到PEM
- Swashbuckle.AspNetCore v1.0.0 with OAuth2,flow:application – > IdentityServer4
- 将NLog连接并注入.Net Core控制台应用程序
- Store未实现IUserRoleStore ASP.NET Core 2.1 Identity
- 是否可以使用.net core Roslyn编译器编译单个C#代码文件?
- Docker在VS中运行但在发布到AWS时出错? 错误CS5001:程序不包含适用于入口点的静态“主”方法
- 在.NET Core项目中找不到System.ServiceModel