문제

The suggested way of using ServiceStack.NET with Silverlight is to use the Linked-Project addon. This enables two synchronous Projects and their sources, one for Silverlight, one for .NET 3.5+.

But when it comes to validation, this gets a bit annoying. ServiceStack is using FluentValidation, which is cool. But it has changed the namespace. So I end up with:

using MyNamespace.Model;

// HERE ----------------------------
#if SILVERLIGHT
using FluentValidation;
#else
using ServiceStack.FluentValidation;
#endif
//TO HERE------------------------

namespace HR.RoBP.Contracts.Validators.Model
{
    public class CustomerValidator : AbstractValidator<Customer>
    {
        public CustomerValidator()
        {
            RuleFor(r => r.Name).NotEmpty().NotNull();
        }
    }
}

This is not much, but it gets really annoing when writing a new validator each time. I often forget it, compile, have errors, fix it. I know there is something changed in FluentValidation on ServiceStack.NET.

But must it be in a seperate Namespace?

I think its in the interest of servicestack to keep code files clean. But using the the same validation on client and server forces me to do this.

If there is a elegant way to fix this issue, I would love to hear about it.

도움이 되었습니까?

해결책

You unfortunately can't set a project-wide namespace alias. You could however try to write a template for your validator class that has that boilerplate code built in, and you can easily click Add -> New Item -> Your Validator Template.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top