Search Results for

    Show / Hide Table of Contents

    Class Validator<TRequest>

    inherit from this base class to define your dto validators

    HINT: validators are registered as singletons. i.e. the same validator instance is used to validate each request for best performance. hance, do not maintain state in your validators.

    Inheritance
    object
    AbstractValidator<TRequest>
    Validator<TRequest>
    Implements
    IValidator<TRequest>
    IValidator
    IEnumerable<IValidationRule>
    IEnumerable
    IServiceResolverBase
    Inherited Members
    AbstractValidator<TRequest>.Validate(TRequest)
    AbstractValidator<TRequest>.ValidateAsync(TRequest, CancellationToken)
    AbstractValidator<TRequest>.Validate(ValidationContext<TRequest>)
    AbstractValidator<TRequest>.ValidateAsync(ValidationContext<TRequest>, CancellationToken)
    AbstractValidator<TRequest>.CreateDescriptor()
    AbstractValidator<TRequest>.RuleFor<TProperty>(Expression<Func<TRequest, TProperty>>)
    AbstractValidator<TRequest>.Transform<TProperty, TTransformed>(Expression<Func<TRequest, TProperty>>, Func<TProperty, TTransformed>)
    AbstractValidator<TRequest>.Transform<TProperty, TTransformed>(Expression<Func<TRequest, TProperty>>, Func<TRequest, TProperty, TTransformed>)
    AbstractValidator<TRequest>.RuleForEach<TElement>(Expression<Func<TRequest, IEnumerable<TElement>>>)
    AbstractValidator<TRequest>.TransformForEach<TElement, TTransformed>(Expression<Func<TRequest, IEnumerable<TElement>>>, Func<TElement, TTransformed>)
    AbstractValidator<TRequest>.TransformForEach<TElement, TTransformed>(Expression<Func<TRequest, IEnumerable<TElement>>>, Func<TRequest, TElement, TTransformed>)
    AbstractValidator<TRequest>.RuleSet(string, Action)
    AbstractValidator<TRequest>.When(Func<TRequest, bool>, Action)
    AbstractValidator<TRequest>.When(Func<TRequest, ValidationContext<TRequest>, bool>, Action)
    AbstractValidator<TRequest>.Unless(Func<TRequest, bool>, Action)
    AbstractValidator<TRequest>.Unless(Func<TRequest, ValidationContext<TRequest>, bool>, Action)
    AbstractValidator<TRequest>.WhenAsync(Func<TRequest, CancellationToken, Task<bool>>, Action)
    AbstractValidator<TRequest>.WhenAsync(Func<TRequest, ValidationContext<TRequest>, CancellationToken, Task<bool>>, Action)
    AbstractValidator<TRequest>.UnlessAsync(Func<TRequest, CancellationToken, Task<bool>>, Action)
    AbstractValidator<TRequest>.UnlessAsync(Func<TRequest, ValidationContext<TRequest>, CancellationToken, Task<bool>>, Action)
    AbstractValidator<TRequest>.Include(IValidator<TRequest>)
    AbstractValidator<TRequest>.Include<TValidator>(Func<TRequest, TValidator>)
    AbstractValidator<TRequest>.GetEnumerator()
    AbstractValidator<TRequest>.EnsureInstanceNotNull(object)
    AbstractValidator<TRequest>.RaiseValidationException(ValidationContext<TRequest>, ValidationResult)
    AbstractValidator<TRequest>.OnRuleAdded(IValidationRule<TRequest>)
    AbstractValidator<TRequest>.CascadeMode
    AbstractValidator<TRequest>.ClassLevelCascadeMode
    AbstractValidator<TRequest>.RuleLevelCascadeMode
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: FastEndpoints
    Assembly: FastEndpoints.dll
    Syntax
    public abstract class Validator<TRequest> : AbstractValidator<TRequest>, IValidator<TRequest>, IValidator, IEnumerable<IValidationRule>, IEnumerable, IServiceResolverBase where TRequest : notnull
    Type Parameters
    Name Description
    TRequest

    the type of the request dto

    Methods

    CreateScope()

    if you'd like to resolve scoped or transient services from the MS DI container, obtain a service scope from this method and dispose the scope when the work is complete.

    <pre><code class="lang-csharp">using var scope = CreateScope();
    var scopedService = scope.Resolve<MyService>();</code></pre>
    
    Declaration
    public IServiceScope CreateScope()
    Returns
    Type Description
    IServiceScope

    PreValidate(ValidationContext<TRequest>, ValidationResult)

    Determines if validation should occur and provides a means to modify the context and ValidationResult prior to execution. If this method returns false, then the ValidationResult is immediately returned from Validate/ValidateAsync.

    Declaration
    protected override bool PreValidate(ValidationContext<TRequest> context, ValidationResult result)
    Parameters
    Type Name Description
    ValidationContext<TRequest> context
    ValidationResult result
    Returns
    Type Description
    bool
    Overrides
    FluentValidation.AbstractValidator<TRequest>.PreValidate(FluentValidation.ValidationContext<TRequest>, FluentValidation.Results.ValidationResult)

    Resolve(Type)

    resolve an instance for the given type from the dependency injection container. will throw if unresolvable.

    Declaration
    public object Resolve(Type typeOfService)
    Parameters
    Type Name Description
    Type typeOfService

    the type of the service to resolve

    Returns
    Type Description
    object
    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if requested service cannot be resolved

    Resolve(Type, string)

    resolve an instance for the given type from the dependency injection container. will throw if unresolvable.

    Declaration
    public object Resolve(Type typeOfService, string keyName)
    Parameters
    Type Name Description
    Type typeOfService

    the type of the service to resolve

    string keyName

    the key name for resolving keyed service

    Returns
    Type Description
    object
    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if requested service cannot be resolved

    Resolve<TService>()

    resolve an instance for the given type from the dependency injection container. will throw if unresolvable.

    Declaration
    public TService Resolve<TService>() where TService : class
    Returns
    Type Description
    TService
    Type Parameters
    Name Description
    TService

    the type of the service to resolve

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if requested service cannot be resolved

    Resolve<TService>(string)

    resolve an instance for the given type from the dependency injection container. will throw if unresolvable.

    Declaration
    public TService Resolve<TService>(string keyName) where TService : class
    Parameters
    Type Name Description
    string keyName

    the key name for resolving keyed service

    Returns
    Type Description
    TService
    Type Parameters
    Name Description
    TService

    the type of the service to resolve

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if requested service cannot be resolved

    TryResolve(Type)

    try to resolve an instance for the given type from the dependency injection container. will return null if unresolvable.

    Declaration
    public object? TryResolve(Type typeOfService)
    Parameters
    Type Name Description
    Type typeOfService

    the type of the service to resolve

    Returns
    Type Description
    object

    TryResolve(Type, string)

    try to resolve an instance for the given type from the dependency injection container. will return null if unresolvable.

    Declaration
    public object? TryResolve(Type typeOfService, string keyName)
    Parameters
    Type Name Description
    Type typeOfService

    the type of the service to resolve

    string keyName

    the key name for resolving keyed service

    Returns
    Type Description
    object

    TryResolve<TService>()

    try to resolve an instance for the given type from the dependency injection container. will return null if unresolvable.

    Declaration
    public TService? TryResolve<TService>() where TService : class
    Returns
    Type Description
    TService
    Type Parameters
    Name Description
    TService

    the type of the service to resolve

    TryResolve<TService>(string)

    try to resolve an instance for the given type from the dependency injection container. will return null if unresolvable.

    Declaration
    public TService? TryResolve<TService>(string keyName) where TService : class
    Parameters
    Type Name Description
    string keyName

    the key name for resolving keyed service

    Returns
    Type Description
    TService
    Type Parameters
    Name Description
    TService

    the type of the service to resolve

    Implements

    FluentValidation.IValidator<T>
    FluentValidation.IValidator
    IEnumerable<T>
    IEnumerable
    IServiceResolverBase
    In this article
    Back to top Developed by Đĵ ΝιΓΞΗΛψΚ and contributors / Licensed under MIT / Website generated by DocFX