2016-06-28 29 views
7

.net RC2'den RTM'ye yükselttikten sonra, ArrayPool'dan türetilen bir JsonOutputFormatter yapıcısına bir parametre sağlamanız gerektiğini buluyorum. Bu nesneyi nasıl alabilirim? Ben JsonOutputFormatter'ı manuel olarak güncelliyorum çünkü ReferenceLoopHandling'i yapılandırmam gerekiyor. yorumlarda https://github.com/aspnet/Mvc/issues/4562ArrayPool nesnesini JsonOutputFormatter yapıcısına sağlayın

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... 
    }  

cevap

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

Source

: it oluştururken

JsonOutputFormatter artık ArrayPool ihtiyacı bulabildiğim

Sadece ilgili diğer bilgiler şudur , ArrayPo'dan geçebilirsin ol.Shared.

Ayrıca ArrayPool'da bir .Create() yöntemi olduğunu fark ettim.

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