Offer for ServiceStack.NET

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

But when it comes to validation, it gets a little annoying. ServiceStack uses FluentValidation which is great. But he changed the namespace. So I get:

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();
        }
    }
}

      

It's not much, but it gets really annoing when you write a new validator every time. I often forget about it, compile, fix bugs. I know something has changed in FluentValidation on ServiceStack.NET.

But should it be in a separate namespace?

I think it is in the utility's interest to keep the code files clean. But using the same validation on client and server forces me to do this.

If there is an elegant way to fix this problem, I'd love to hear about it.

+3


source to share


1 answer


You are unfortunately unable to set a namespace alias for the entire project . However, you can try to create a template for your validator class that has inline template code and you can easily click Add -> New Item -> Your Validator Template.



+2


source







All Articles