Ninjects with fluentvalidation

I am looking for some help on how to implement a fluidization structure using ninjects as a DI framework.

There is a ninject extension, but I cannot find documentation on how to use it. Where can you find documentation / tutorial on setting up these very good frameworks?

Vb.net Solution

Public Class Dinner

Public Property DinnerID As Guid

Public Property Title As String

Public Property EventDate As DateTime

Public Property Address As String

Public Property HostedBy As String

Public Overridable Property RSVPs As ICollection(Of RSVP)

End Class



Imports FluentValidation

    Public Class dinnervalidator
        Inherits AbstractValidator(Of Dinner)

        Public Sub New()
            RuleFor(Function(x) x.EventDate).NotEmpty().WithMessage("Gelieve een geldige eventdatum op te geven")
            RuleFor(Function(x) x.Address).NotEmpty().WithMessage("Gelieve een adres in te vullen").Length(5, 50).WithMessage("Gelieve een Geldig adres in te vullen aub")
        End Sub
    End Class

Public Class fluentvalidationmodule
    Inherits NinjectModule

    Public Overrides Sub Load()
        AssemblyScanner.FindValidatorsInAssemblyContaining(Of dinnervalidator) _
            .ForEach(Function(x) Bind(x.InterfaceType).To(x.ValidatorType))

    End Sub

End Class
+3
source share
2 answers

The readme for the Fuzzy Flag Checker is pretty explicit:

To use the following steps:

Connect ASP.NET MVC to using NinjectValidatorFactory:

NinjectValidatorFactory ninjectValidatorFactory = 
    new NinjectValidatorFactory(ninjectKernel); 
ModelValidatorProviders.Providers.Add(
    new FluentValidationModelValidatorProvider(ninjectValidatorFactory));
DataAnnotationsModelValidatorProvider.
    AddImplicitRequiredAttributeForValueTypes = false;

Add a module to your project that will bind all your validators:

public class FluentValidatorModule : NinjectModule { 
    public override void Load() { 
        AssemblyScanner.FindValidatorsInAssemblyContaining().ForEach(
            match => Bind(match.InterfaceType).To(match.ValidatorType)); 
    } 
}
+4
source
public class FluentValidatorModule : NinjectModule
{
    public override void Load()
    {
        //  NOTE: it should have: <IValidator>()

        AssemblyScanner.FindValidatorsInAssemblyContaining<IValidator>()
            .ForEach(match => Bind(match.InterfaceType).To(match.ValidatorType));
    }
}
+3
source

All Articles