2016-06-28 9 views
7

Dopo l'aggiornamento da .net RC2 a RTM, trovo necessario fornire un parametro a un costruttore di JsonOutputFormatter che deriva da ArrayPool. Come ottengo questo oggetto? Sto aggiornando manualmente JsonOutputFormatter perché devo configurare ReferenceLoopHandling.Fornire oggetto ArrayPool al costruttore JsonOutputFormatter

Solo altre informazioni correlate che ho trovato è questo: 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... 
    }  

risposta

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

Source

Nei commenti:

Il JsonOutputFormatter ora ha bisogno di un ArrayPool durante la creazione di esso , è possibile passare in ArrayPo ol.Shared.

Ho anche notato che esiste un metodo .Create() su ArrayPool.

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