Skip to content

Commit

Permalink
Merge pull request #43 from SharpGrip/38-mvc-autovalidation-not-perfo…
Browse files Browse the repository at this point in the history
…rmed-with-a-null-binding-source

add null binding source
  • Loading branch information
mvdgun authored Dec 4, 2024
2 parents ccc4eec + 4550942 commit 21c66e4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public class AutoValidationMvcConfiguration
/// </summary>
public bool EnableCustomBindingSourceAutomaticValidation { get; set; } = false;

/// <summary>
/// Enables asynchronous automatic validation for parameters not bound from any binding source (typically parameters without a declared or inferred binding source).
/// </summary>
public bool EnableNullBindingSourceAutomaticValidation { get; set; } = false;

/// <summary>
/// Holds the overridden result factory. This property is meant for infrastructure and should not be used by application code.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ private bool HasValidBindingSource(BindingSource? bindingSource)
(autoValidationMvcConfiguration.EnableFormBindingSourceAutomaticValidation && bindingSource == BindingSource.Form) ||
(autoValidationMvcConfiguration.EnableQueryBindingSourceAutomaticValidation && bindingSource == BindingSource.Query) ||
(autoValidationMvcConfiguration.EnablePathBindingSourceAutomaticValidation && bindingSource == BindingSource.Path) ||
(autoValidationMvcConfiguration.EnableCustomBindingSourceAutomaticValidation && bindingSource == BindingSource.Custom);
(autoValidationMvcConfiguration.EnableCustomBindingSourceAutomaticValidation && bindingSource == BindingSource.Custom) ||
(autoValidationMvcConfiguration.EnableNullBindingSourceAutomaticValidation && bindingSource == null);
}

private void HandleUnvalidatedEntries(ActionExecutingContext context)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ app.MapPost("/", (SomeOtherModel someOtherModel) => $"Hello again {someOtherMode
| EnableQueryBindingSourceAutomaticValidation | `true` | Enables asynchronous automatic validation for parameters bound from `BindingSource.Query` binding sources (typically parameters decorated with the `[FromQuery]` attribute). |
| EnablePathBindingSourceAutomaticValidation | `false` | Enables asynchronous automatic validation for parameters bound from `BindingSource.Path` binding sources (typically parameters decorated with the `[FromRoute]` attribute). |
| EnableCustomBindingSourceAutomaticValidation | `false` | Enables asynchronous automatic validation for parameters bound from `BindingSource.Custom` binding sources. |
| EnableNullBindingSourceAutomaticValidation | `false` | Enables asynchronous automatic validation for parameters not bound from any binding source (typically parameters without a declared or inferred binding source). |

```
using SharpGrip.FluentValidation.AutoValidation.Mvc.Extensions;
Expand Down

0 comments on commit 21c66e4

Please sign in to comment.