【发布时间】:2016-06-28 19:11:28
【问题描述】:
从 .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<MvcOptions>(options =>
{
options.OutputFormatters.RemoveType<JsonOutputFormatter>();
options.OutputFormatters.Insert(0, formatter);
});
//etc...
}
【问题讨论】:
标签: c# json.net asp.net-core .net-core