流動性検証が基本Service-Stackアプリケーション内で発生するようなことを見落とさなければなりません。 私はhereの例に従っています。私の人生のために、私はバリデーターを発射することができないでしょうか? クラムス、私は行方不明の何か愚かでなければならない.... ???ServiceStackとFluentValidationが発動しない
私はユーザーサービス(http://my.service/users)に対してユーザーリクエストを発行していますが、要求は登録された適切なバリデーターを呼び出さずにまっすぐに進みます。
要求である: { "名前": ""、 "会社": "CO"、 "年齢" 10、 "カウント" 110、 "住所"、 "123褐色STRを"}
応答: "ユーザー保存..." ここで
コードは次のとおりです。 1.DTO
[Route("/users")]
public class User
{
public string Name { get; set; }
public string Company { get; set; }
public int Age { get; set; }
public int Count { get; set; }
public string Address { get; set; }
}
2.Validator
public class UserValidator : AbstractValidator<User>
{
public UserValidator()
{
RuleFor(r => r.Name).NotEmpty();
RuleFor(r => r.Age).GreaterThan(0);
}
}
3.AppHostBase
public class ValidationAppHost : AppHostBase
{
public ValidationAppHost()
: base("Validation Test", typeof(UserService).Assembly)
{
}
public override void Configure(Funq.Container container)
{
Plugins.Add(new ValidationFeature());
//This method scans the assembly for validators
container.RegisterValidators(typeof(UserValidator).Assembly);
}
}
4.Service
public class UserService : Service
{
public object Any(User user)
{
return "user saved...";
}
}
5.Global.asax.cs
protected void Application_Start(object sender, EventArgs e)
{
new ValidationAppHost().Init();
}
何も目立ちません。どのようにあなたのリクエストを投稿していますか?最後にフォーマット(http://my.service/users?format = json)を追加すると応答が変更されますか? – paaschpa
私はちょうどGoogle Chrome Appを使用しています。 [REST-Console](http://codeinchaos.com/post/3610180596/rest-console-a-google-chrome-rest-http-client)。私は標準のASP.NET Webサイトのlocalhostインスタンスに対してJSONを実行しています。 – darthal
hmm ...あなたのコードをコピーし、RESTコンソールの設定 'Target> Request URI' = localhost/users、 'Target> Request Method' = POST、 'Body> Content Type' = application/json、 'Body> RAW BODy' = {あなたのリクエスト}と[送信]をクリックして検証を開始しました。その他のフィールドはすべてREST-Consoleが空です(リクエストパラメータなど)?また、プラグイン/フィルタが正しく設定されているかどうかを確認するためのhttp://stackoverflow.com/questions/15297745/servicestack-validation-not-always-firing/15345117#15345117を参照してください。 – paaschpa