将 ArrayPool 对象提供给 JsonOutputFormatter 构造函数

Provide ArrayPool object to JsonOutputFormatter constructor

从 .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...
    }    
var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Shared);

Source

在评论中:

The JsonOutputFormatter now needs a ArrayPool when creating it, you can pass in ArrayPool.Shared.

我还注意到 ArrayPool 上有一个 .Create() 方法。

var formatter = new JsonOutputFormatter(formatterSettings, ArrayPool<Char>.Create());