Should support params to work with
Description
Environment
Activity
Dario Quintana November 20, 2009 at 5:19 AM
Resolved with Fluent + Satisfy features.
Fabio Maulo August 20, 2008 at 3:48 PM
I continue without understand the point/advantage to use NHV in that way.
Each rule work with a property/field, do you are supposing that Foo and OtherFoo have same property/fields without implement a common interface ?
Dario Quintana August 19, 2008 at 12:39 PM
Yes, the idea is to change validator at runtime, further, to change values to valid with.
For example, in a Asp.net applicacion, in order to pass parameters into the IsValid method you can use the Session or some global mechanims to get the values to use in this scope. This is the main problem to solve: obtain values passed from the validator-caller (whom call the Validate or IsValid).
public bool IsValid(object entity)
{
///
}
The idea is use the ValidatorEngine (as usual), but if some validation need values, that values should be provided when the methods IsValid or Validate are called.
As you can see the last example show the IsValid at the end of the chain, some kind of "detached" object should be passed first.
Dario Quintana August 19, 2008 at 12:27 PM
Yesterday I scratch out this lines:
==========================================================
entity = GetEntity();
result = ve.With<FooValidator>(c => c.Foo,new FooArgs(fooCollection))
.With<FooValidator>(c => c.OtherFoo, new FooArgs(otherCollection))
.IsValid(entity);
==========================================================
public class FooValidator : IValidator, ValidationArgs<FooArgs>
{
IList someCollection;
public bool IsValid(object entity)
{
return someCollection.Contains(entity);
}
public void Initialize(FooArgs args)
{
someCollection = args.Collection;
}
}
==========================================================
But... I prefer this:
ve.With(new Params<MyEntity>().Param<FooValidator>("Foo",new FooArgs(fooCollection))
.Param<FooValidator>("OtherFoo",new FooArgs(otherCollection))
).IsValid(entity);
==========================================================
ve.With(new Params<MyEntity>()
.Param<FooValidator>(c => c.Foo, new FooArgs(fooCollection))
.Param<FooValidator>(c => c.OtherFoo, new FooArgs(otherCollection))
).IsValid(entity);
Fabio Maulo August 7, 2008 at 3:53 PM
Property of customer where apply it ?
This is to change the validator at run-time ?
What happen with validatorEngine ? we are supporting only one ClassValidator per Class.
Possibilities:
1)
validatorEngine.Validate(customer,new MyRuleArgs(param1,param2,param3))
validatorEngine.IsValid(customer,new MyRuleArgs(param1,param2,param3))
OR
2)
validatorEngine.WithRules<MyValidator1>()
.Use(new MyRule2Args(param1,param2,param3))
.WithRules<MyValidator2>()
.Use(new MyRule2Args(param4,param5,param6))
.Validate(customer);
validatorEngine.WithRules<MyValidator1>()
.Use(new MyRule1Args(param1,param2,param3))
.WithRules<MyValidator2>()
.Use(new MyRule2Args(param4,param5,param6))
.IsValid(customer);