Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not validate for primitive objects. #5923

Merged
merged 2 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion docs/en/Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ namespace Acme.BookStore

> ABP framework uses the [dynamic proxying / interception](Dynamic-Proxying-Interceptors.md) system to perform the validation. In order to make it working, your method should be **virtual** or your service should be injected and used over an **interface** (like `IMyService`).

#### Enabling/Disabling Validation

You can use the `[DisableValidation]` to disable it for methods, classs and properties.

````csharp
[DisableValidation]
public Void MyMethod()
{
}

[DisableValidation]
public class InputClass
{
public string MyProperty { get; set; }
}

public class InputClass
{
[DisableValidation]
public string MyProperty { get; set; }
}
````

### AbpValidationException

Once ABP determines a validation error, it throws an exception of type `AbpValidationException`. Your application code can throw `AbpValidationException`, but most of the times it is not needed.
Expand Down Expand Up @@ -155,4 +178,4 @@ public class MyObjectValidationContributor

## FluentValidation Integration

Volo.Abp.FluentValidation package integrates the FluentValidation library to the validation system (by implementing the `IObjectValidationContributor`). See the [FluentValidation Integration document](FluentValidation.md) for more.
Volo.Abp.FluentValidation package integrates the FluentValidation library to the validation system (by implementing the `IObjectValidationContributor`). See the [FluentValidation Integration document](FluentValidation.md) for more.
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ protected virtual void ValidateObjectRecursively(List<ValidationResult> errors,
AddErrors(errors, validatingObject);

//Validate items of enumerable
if (validatingObject is IEnumerable)
if (validatingObject is IEnumerable enumerable)
{
if (!(validatingObject is IQueryable))
if (!(enumerable is IQueryable))
{
foreach (var item in (validatingObject as IEnumerable))
foreach (var item in enumerable)
{
//Do not recursively validate for primitive objects
if (TypeHelper.IsPrimitiveExtended(item.GetType()))
{
break;
}

ValidateObjectRecursively(errors, item, currentDepth + 1);
}
}
Expand Down Expand Up @@ -124,4 +130,4 @@ protected virtual void AddPropertyErrors(object validatingObject, PropertyDescri
}
}
}
}
}