我正在寻找一些关于如何使用ninjects作为DI框架实现流畅验证框架的帮助. 有一个ninject扩展,但我找不到如何使用它的文档. 在哪里可以找到设置这些非常好的框架的文档/教程? Vb.net解决
有一个ninject扩展,但我找不到如何使用它的文档.
在哪里可以找到设置这些非常好的框架的文档/教程?
Vb.net解决方案
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 ClassNinject Fluent Validation module的 readme非常明确:
To use follow these steps:
Wire up ASP.NET MVC to use the
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 of your validators:
public class FluentValidatorModule : NinjectModule { public override void Load() { AssemblyScanner.FindValidatorsInAssemblyContaining().ForEach( match => Bind(match.InterfaceType).To(match.ValidatorType)); } }