2016-04-22 18 views
5

Sto scrivendo un webhook in asp.net core mvc dove il chiamante pubblica alcuni json. Ma il Content-Type è impostato su application/vnd.myget.webhooks.v1+json. Voglio solo avere questo tipo di contenuto map per il JsonInputFormatter.Aggiungi MediaType a JsonInputFormatter esistente

ho fatto questo, ma chiedo se c'è un modo migliore:

services.AddMvc(mvcConfig => 
{ 
    var formatter = new JsonInputFormatter(); 
    formatter.SupportedMediaTypes.Add( 
     new MediaTypeHeaderValue("application/vnd.myget.webhooks.v1+json")); 
    mvcConfig.InputFormatters.Add(formatter); 
}); 

risposta

3

È possibile modificare il valore predefinito InputFormatter in ConfigureServices

services.Configure<MvcOptions>(options => { 
    options.InputFormatters.OfType<JsonInputFormatter>().First().SupportedMediaTypes.Add(
     new MediaTypeHeaderValue("application/vnd.myget.webhooks.v1+json") 
    ); 
}); 

... forse un leggero miglioramento

Problemi correlati