从 .net RC2 升级到 RTM 后,我发现我需要向派生自 ArrayPool 的 JsonOutputFormatter 构造函数提供一个参数。我如何获得这个对象?我手动新建 JsonOutputFormatter 因为我需要配置 ReferenceLoopHandling。
我只能找到的其他相关信息是:https://github.com/aspnet/Mvc/issues/4562 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<MvcOptions>(options =>
{
options.OutputFormatters.RemoveType<JsonOutputFormatter>();
options.OutputFormatters.Insert(0, formatter);
});
//etc...
}
var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Shared);
Source https://wildermuth.com/2016/06/27/Converting-ASP-NET-Core-1-0-RC2-to-RTM-Bits
在评论中:
JsonOutputFormatter 现在在创建它时需要一个 ArrayPool,您
可以传入ArrayPool.Shared。
我还注意到 ArrayPool 上有一个 .Create() 方法。
var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Create());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)