We want this change to avoid MVC eagerly reading the form. This is good
for general perf and also for scenarios where you want read the body
yourself (large file uploads).
We DO have scenarios where you want to configure the value providers
per-request or also to change the limits on the value providers (form) so
it's worth keeping these around on the context.
This change no longer suppresses validation for IFormFile and
IFormFileCollection model values. This will allow the use of [Required] on an
IFormFile model, or a custom attribute for validating IFormFileCollection.
These types already have ValidateChildren = false, so we don't recurse
into them.
This change separates model binding into IModelBinderProvider (decides
which binder to use) and IModelBinder (does binding). The
IModelBinderFactory is a new services with coordinates the creation of
model binders.
- #3482
- see new tests; many failed without fixes in the product code
- add support for binding `IFormFileCollection` properties
- make `FormFileModelBinder` / `HeaderModelBinder` collection handling consistent w/ `GenericModelBinder`++
- see also dupe bug #4129 which describes some of the prior inconsistencies
- add checks around creating collections and leaving non-top-level collections `null` (not empty)
- move smarts down to `ModelBindingHelper.GetCompatibleCollection<T>()` (was `ConvertValuesToCollectionType<T>()`)
- add `ModelBindingHelper.CanGetCompatibleCollection()`
- add fallback for cases like `public IEnumerable<T> Property { get; set; } = new T[0];`
- #4193
- allow `Exception`s while activating collections to propagate
- part of #4181
- `CollectionModelBinder` no longer creates an instance to check if it can create an instance
- not a complete fix since it still creates unnecessary intermediate lists
nits:
- correct a few existing test names since nothing is not the same as `ModelBindingResult.Failed()`
- remove a couple of unnecessary `return` statements
- correct stale "optimized" comments
- explicit `(string)`