Git Product home page Git Product logo

mediatr.extensions.fluentvalidation.aspnetcore's People

Contributors

getoxs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mediatr.extensions.fluentvalidation.aspnetcore's Issues

Error: MissingMethodException

Packages installed:

  • .NET 6 Preview
  • FluentValidation 10.3.3
  • MediatR.Extensions.FluentValidation.AspNetCore 1.2.0
var applicationAssembly = typeof(CreateUserValidator).Assembly;

services.AddMediatR(applicationAssembly);
services.AddFluentValidation(new []{ applicationAssembly });
System.MissingMethodException: Method not found: 'FluentValidation.AssemblyScanner FluentValidation.AssemblyScanner.FindValidatorsInAssembly(System.Reflection.Assembly)'.
   at FluentValidation.ServiceCollectionExtensions.AddValidatorsFromAssembly(IServiceCollection services, Assembly assembly, ServiceLifetime lifetime, Func`2 filter)
   at FluentValidation.ServiceCollectionExtensions.AddValidatorsFromAssemblies(IServiceCollection services, IEnumerable`1 assemblies, ServiceLifetime lifetime, Func`2 filter) in C:\Projects\FluentValidation\src\FluentValidation.DependencyInjectionExtensions\ServiceCollectionExtensions.cs:line 36
   at MediatR.Extensions.FluentValidation.AspNetCore.ServiceCollectionExtensions.AddFluentValidation(IServiceCollection services, IEnumerable`1 assemblies, ServiceLifetime lifetime, Func`2 filter)
   at ...

RuleForEach(x => x.items).SetValidator(new ItemValidator()) not validating

Hi, first of all thank you for your work, that package is so usefull.

Now the problem.
I'm trying to validate a collection of DTOs with RuleForEach and setting a validator of another class with SetValidator and is not detecting the validation.

If I try to validate inside the Handler manually is working perfect.

Missing the parameter "includeInternalTypes"

When using the extension method to register the validators:

builder.Services.AddFluentValidation(new[] { assembly });

It misses the parameter includeInternalTypes for services.AddValidatorsFromAssemblies

public static class ServiceCollectionExtensions
{
  public static IServiceCollection AddFluentValidation(this IServiceCollection services,
                                                       IEnumerable<Assembly> assemblies,
                                                       ServiceLifetime lifetime = ServiceLifetime.Transient,
                                                       Func<AssemblyScanner.AssemblyScanResult, bool>? filter = null,
                                                       bool includeInternalTypes = false)
  {
    services.Add(new ServiceDescriptor(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>), lifetime));
    services.AddValidatorsFromAssemblies(assemblies, lifetime, filter, includeInternalTypes);

    return services;
  }
}

The nuget is created in wrong way.

Unhandled exception. System.MissingMethodException: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection FluentValidation.ServiceCollectionExtensions.AddValidatorsFromAssemblies(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Collections.Generic.IEnumerable`1<Sy
stem.Reflection.Assembly>, Microsoft.Extensions.DependencyInjection.ServiceLifetime)'.
   at MediatR.Extensions.FluentValidation.AspNetCore.ServiceCollectionExtensions.AddFluentValidation(IServiceCollection services, IEnumerable`1 assemblies, ServiceLifetime lifetime)

When I copied code directly - it worked.

AddFluentValidation breaks with MediatR 10

Hello,

It seems that the update to MediatR 10 breaks this extension, probably because the contracts were moved to another assembly.
Is it possible to update the lib to handle this new version?

Does not work for IRequest (Mediatr 12)

Describe the bug
Validation does not work for IRequest (not generic)

To Reproduce
Steps to reproduce the behavior:

using MediatR;

public sealed class Command : IRequest
{
     public string Name { get; set; }
}

public sealed class CommandValidator : AbstractValidator<Command> {
     RuleFor(x => x.Name).NotEmpty();
}

Send mediatr request with this command and Name = null.

Expected behavior
Validation does not work.

Library (please complete the following information):

  • Version 4.0.0

Additional context
You need change IRequest<TResponse> to IBaseRequest as like

public sealed class ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
    where TRequest : class, IBaseRequest

Package breaks with FluentValidation v 11

MediatR.Extensions.FluentValidation.AspNetCore is broken with FluentValidation version 11. It worked fine in FluentValidation version 10. However, after upgrading to 11.0.1, the application breaks on start throwing the following exception from service.AddFluentValidation:

System.MissingMethodException
HResult=0x80131513
Message=Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection FluentValidation.ServiceCollectionExtensions.AddValidatorsFromAssemblies(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Collections.Generic.IEnumerable1<System.Reflection.Assembly>, Microsoft.Extensions.DependencyInjection.ServiceLifetime, System.Func2<AssemblyScanResult,Boolean>)'.
Source=MediatR.Extensions.FluentValidation.AspNetCore
StackTrace:
at MediatR.Extensions.FluentValidation.AspNetCore.ServiceCollectionExtensions.AddFluentValidation(IServiceCollection services, IEnumerable1 assemblies, ServiceLifetime lifetime, Func2 filter)
at Api.Startup.ConfigureServices(IServiceCollection services) in C:[project folder omitted]\Startup.cs:line 100
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Api.Program.Main(String[] args) in C:[project folder omitted]\Program.cs:line 12

I opened a bug with FluentValidation, but they closed it saying this is a problem with MediatR.Extensions.FluentValidation.AspNetCore. You can see that issue here for reference: FluentValidation/FluentValidation#1939

They say you will "need to publish a new version of this package that’s compatible with FluentValidation 11 (they should just need to recompile targeting FV 11). They should also ensure that they lock their dependency versions in line with SemVer to not auto upgrade across major versions to prevent issues like this in the future."

Run validation in an async context to allow async rules in FluentValidation v11

Is your feature request related to a problem? Please describe.
Until now FluentValidation, async rules were silently run as synchronous, so they could be used.
Since v11, it now throws an exception when an async rule is executed synchronously, a lot of our validators are now throwing exceptions when validating a command.

Describe the solution you'd like
Very very quickly looking at the code, it looks like the Validate() is already running in an async context.
So it should be possible to call ValidateAsync instead of Validate, allowing to use async rules without too much impact.
Could it be possible to change the code to do that ?

RuleSet

Hello,
Is it possible to use RuleSet for validation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.