Found a "good enough" solution:
public static class InstanceConstraintExtension
{
public static IChainableConstraint<IInstanceConstraints<TEntity>>
With<TValidator, TEntity>(this IInstanceConstraints<TEntity> constraints)
where TValidator : IValidator
where TEntity : class
{
return constraints.By(IoC.Resolve<TValidator>().IsValid);
}
}
Usage:
ValidateInstance.With<MyValidator, MyEntity>();
On Fri, Apr 30, 2010 at 3:10 PM, Valeriu Caraulean <[email protected]>wrote:
> I was thinking about how to simplify and make more consistent registration
> of validators.
> We have few custom validators (implementing IValidator) that are using
> injected services to validate things. Those validators are linked to
> entities with attributes. I'd prefer to have all validation rules to be
> declared in one single place. ValidationDef is looking like a good place for
> it: gather together all validation rules...
>
> I'm playing now with idea of something like
> ValidateInstance.With<TValidator>() where TValidator : IValidator
> and having TValidator being resolved from container. Is it a good idea?
>
>
> On Fri, Apr 30, 2010 at 2:00 AM, Fabio Maulo <[email protected]> wrote:
>
>> can you explain why ?
>> ValidationDef are used only one time during configuration.
>> You can add instances of ValidationDef to the configuration avoiding the
>> "multi-validationDef" registration which will use the Activator and the
>> parameter less ctor.
>> The methos is:
>> Register<TEntity>(IValidationDefinition<TEntity> validationDefinition)
>>
>>
>> On Thu, Apr 29, 2010 at 10:05 AM, Valeriu Caraulean
>> <[email protected]>wrote:
>>
>>> Hi there
>>>
>>> I'd like (for the sake of consistency) to have my ValidationDef's
>>> built trough container and those who have external dependencies will
>>> get them injected.
>>>
>>> Is there any way to have it done in current code base?
>>>
>>> If not, can the introduction of an IValidationDefFactory by analogy
>>> with IConstraintValidatorFactory and using it to create ValidatorDef's
>>> be a good solution? If we'll provide a path for this will it be
>>> accepted?
>>>
>>> Thanks
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "NHibernate Contrib - Development Group" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<nhcdevs%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/nhcdevs?hl=en.
>>>
>>>
>>
>>
>> --
>> Fabio Maulo
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "NHibernate Contrib - Development Group" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<nhcdevs%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/nhcdevs?hl=en.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"NHibernate Contrib - Development Group" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhcdevs?hl=en.