public TransactionProcessor(IInputFormatter inputFormatter) { _inputFormatter = inputFormatter; }
private static BodyModelBinder GetBodyBinder(IInputFormatter inputFormatter) { return(GetBodyBinder(new DefaultHttpContext(), inputFormatter)); }
public RequestReader(HttpContext httpContext, IInputFormatter inputFormatter) { _httpContext = httpContext; _inputFormatter = inputFormatter; }
/// <summary> /// Asynchronously read the body content as the specified type. /// </summary> /// <typeparam name="TBody"> /// The CLR data-type that the body content will be deserialised into. /// </typeparam> /// <param name="content"> /// The <see cref="HttpContent"/> to read. /// </param> /// <param name="formatter"> /// The content formatter used to deserialise the body content. /// </param> /// <param name="formatterContext"> /// Contextual information about the content body being deserialised. /// </param> /// <returns> /// The deserialised body content. /// </returns> public static async Task <TBody> ReadAsAsync <TBody>(this HttpContent content, IInputFormatter formatter, InputFormatterContext formatterContext) { if (content == null) { throw new ArgumentNullException(nameof(content)); } if (formatterContext == null) { throw new ArgumentNullException(nameof(formatterContext)); } using (Stream responseStream = await content.ReadAsStreamAsync().ConfigureAwait(false)) { object responseBody = await formatter.ReadAsync(formatterContext, responseStream).ConfigureAwait(false); return((TBody)responseBody); } }
private static BodyModelBinder GetBodyBinder(IInputFormatter inputFormatter) { return GetBodyBinder(new DefaultHttpContext(), inputFormatter); }
private static BodyModelBinder GetBodyBinder(HttpContext httpContext, IInputFormatter inputFormatter) { var actionContext = CreateActionContext(httpContext); var inputFormatterSelector = new Mock<IInputFormatterSelector>(); inputFormatterSelector .Setup(o => o.SelectFormatter( It.IsAny<IReadOnlyList<IInputFormatter>>(), It.IsAny<InputFormatterContext>())) .Returns(inputFormatter); var bodyValidationPredicatesProvider = new Mock<IValidationExcludeFiltersProvider>(); bodyValidationPredicatesProvider.SetupGet(o => o.ExcludeFilters) .Returns(new List<IExcludeTypeValidationFilter>()); var bindingContext = new ActionBindingContext() { InputFormatters = new List<IInputFormatter>(), }; var bindingContextAccessor = new MockScopedInstance<ActionBindingContext>() { Value = bindingContext, }; var binder = new BodyModelBinder( actionContext, bindingContextAccessor, inputFormatterSelector.Object, bodyValidationPredicatesProvider.Object); return binder; }
private static ModelBindingContext GetBindingContext( Type modelType, IInputFormatter inputFormatter = null, HttpContext httpContext = null, IModelMetadataProvider metadataProvider = null) { if (httpContext == null) { httpContext = new DefaultHttpContext(); } if (metadataProvider == null) { metadataProvider = new EmptyModelMetadataProvider(); } var operationBindingContext = new OperationBindingContext { ModelBinder = GetBodyBinder(httpContext, inputFormatter), MetadataProvider = metadataProvider, HttpContext = httpContext, }; var bindingContext = new ModelBindingContext { ModelMetadata = metadataProvider.GetMetadataForType(modelType), ModelName = "someName", ValueProvider = Mock.Of<IValueProvider>(), ModelState = new ModelStateDictionary(), OperationBindingContext = operationBindingContext, BindingSource = BindingSource.Body, }; return bindingContext; }
public static MongoSource <T> CreateFromCollection <T>(string collectionName, IInputFormatter <T> formatter) where T : class { var source = new MongoSource <T>(collectionName); source.SetFormatter(formatter); return(source); }
protected void LogInputFormatterRejected(IInputFormatter formatter, InputFormatterContext formatterContext) { }
private static partial void InputFormatterRejected(ILogger logger, IInputFormatter inputFormatter, string?contentType);
public void AddInputFormatter(IInputFormatter formatter) { _mvcCoreBuilder.AddMvcOptions(o => o.InputFormatters.Add(formatter)); }