public static IMvcCoreBuilder AddMessagePackFormatters(this IMvcCoreBuilder builder, Action <MessagePackFormatterOptions> messagePackFormatterOptionsConfiguration) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } var messagePackFormatterOptions = new MessagePackFormatterOptions(); messagePackFormatterOptionsConfiguration?.Invoke(messagePackFormatterOptions); foreach (var extension in messagePackFormatterOptions.SupportedExtensions) { foreach (var contentType in messagePackFormatterOptions.SupportedContentTypes) { builder.AddFormatterMappings(m => m.SetMediaTypeMappingForFormat(extension, new MediaTypeHeaderValue(contentType))); } } builder.AddMvcOptions(options => { options.InputFormatters.Add(new MessagePackInputFormatter(messagePackFormatterOptions)); options.ModelMetadataDetailsProviders.Add(new DefaultBindingMetadataProvider()); options.ModelMetadataDetailsProviders.Add(new DefaultValidationMetadataProvider()); }); builder.AddMvcOptions(options => options.OutputFormatters.Add(new MessagePackOutputFormatter(messagePackFormatterOptions))); return(builder); }
public MessagePackInputFormatter(MessagePackFormatterOptions messagePackFormatterOptions) { _options = messagePackFormatterOptions ?? throw new ArgumentNullException(nameof(messagePackFormatterOptions)); foreach (var contentType in messagePackFormatterOptions.SupportedContentTypes) { SupportedMediaTypes.Add(new MediaTypeHeaderValue(contentType)); } }