NancyFx FluentValidation problem
I am developing a web framework with Nancy and I decided to use FluentValidation.
Models and validators are in the same Assembly, except for the main [App.Core (models and validators) -> App.Web (bootstrapper, modules, etc.)]
I tried to add the loader AppDomainAssemblyTypeScanner.AddAssembliesToScan ("App.Core"); but no results.
What can I do?
My model and validator:
using System;
using FluentValidation;
namespace App.Core.Modules.Account
{
public class AccountLoginModel : BaseModel
{
public String Username { get; set; }
public string Password { get; set; }
public bool RememberMe { get; set; }
}
public class AccountLoginValidator : AbstractValidator<AccountLoginModel>
{
public AccountLoginValidator()
{
RuleFor(x => x.Username).NotNull().NotEmpty().Length(1, 64).Matches("[A-Z]*");
RuleFor(x => x.Password).NotNull().NotEmpty().Length(8, 64).Matches("[A-Z]*");
}
}
}
My NancyModule
[...]
Post["/login"] = x =>
{
var m = this.BindAndValidate<AccountLoginModel>();
if (!ModelValidationResult.IsValid)
{
Model.BaseModel.AddError("Login errors...");
Model.BaseModel.ReturnUrl = this.Request.Url;
Model.Users = m;
return View["Shared/Account/Login", Model];
}
};
[...]
My Bootstrapper
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
AppDomainAssemblyTypeScanner.AddAssembliesToScan("App.Core");
[...]
}
Thanks everyone!
+3
source to share
No one has answered this question yet
Check out similar questions: