本文介绍了提供ArrayPool对象给JsonOutputFormatter构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从.net RC2升级到RTM后,我发现需要为从ArrayPool派生的JsonOutputFormatter的构造函数提供一个参数.我如何得到这个物体?我要手动更新JsonOutputFormatter,因为我需要配置ReferenceLoopHandling.
After upgrading from .net RC2 to RTM I find I need to supply a parameter to a constructor of JsonOutputFormatter that derives from ArrayPool. How do I get this object? I am newing JsonOutputFormatter manually because I need to configure ReferenceLoopHandling.
我只能找到的其他相关信息是: https://github.com/aspnet/Mvc/issues/4562
Only other related info I could find is this: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);
在评论中:
我还注意到ArrayPool上有一个.Create()方法.
I also noticed there is a .Create() method on ArrayPool.
var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Create());
这篇关于提供ArrayPool对象给JsonOutputFormatter构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!