Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return custom result type from IValitResult<T> and IValitator<T> #161

Open
GooRiOn opened this issue Feb 17, 2018 · 1 comment
Open

Return custom result type from IValitResult<T> and IValitator<T> #161

GooRiOn opened this issue Feb 17, 2018 · 1 comment

Comments

@GooRiOn
Copy link
Member

GooRiOn commented Feb 17, 2018

I think it could be a nice feature to allow defining output result from IValitRules<T> like follows:

ValitRules<Model>
    .Create()
    .Ensure(....)
    .WithResult(r => new MyResult { ....})
    .Validate();

Things are little bit more complicated in IValitator<T> because here we would have to add generic interface like IValitator<TModel,TResult> and create abstract class which would take in the ctor Func<ValitResult, TResult>. But overall I think this would be very cool because folks can add Valit to their projects without changing the existing infrastructure related to error handling. What's your optinion on that one?

@dbarwikowski
Copy link
Member

dbarwikowski commented Apr 3, 2018

Shouldn't we pass it in front of chain, and fill during validation?

ValitRules<Model, Result>
    .Create()
    .Ensure(m => m.Password, 
            _=>_.Contains("1") ,
            r => { 
                    r.Status.Set(ValidationStatus.Invalid);
                    r.Reasons.Add("Password doesn't contain '1'");
            })
    .Validate();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants