EntLib 5 Configuration Utility

Topics: Validation Application Block
Jan 13, 2011 at 3:08 PM

I'm trying to use configuration to validate against interfaces but the utility does not recognize interfaces. Oddly enough, if I setup an a validator against the concrete type, then change the config file to point to the interface, everything works just fine.

Is this an omission or am I missing something?

Jan 14, 2011 at 12:46 AM

We'll ask the EntLib team if this is a bug or a design decision.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 14, 2011 at 10:40 AM

Thanks for looking into this. I found a related odd behavior.

I have a class called Company and a subclass called Customer that have corresponding ICompany and ICustomer interfaces. The ICustomer interface is declared as follows:

public interface ICustomer : ICompany

Validating a Customer (ICustomer) ALWAYS returns Valid as though there are no validations taking place at all. I was able to reproduce this pattern with other inheritance relationships. Again, I can validate ICompany just fine.

This one cetainly does look a lot like a defect.

Thanks in advance

John Caccavaro

Jan 17, 2011 at 12:52 AM

Where are your validation attributes or validators applied to?  Is it on the interface?  Because if yes, then, the validations won't get fired since the new behavior of the Validation.Validate method in EntLib 5.0 is to validate the object based on its actual type.  To validate based on the valdation rules defined on the interface, create a validator first by calling ValidationFactory.CreateValidator<IInterface>() and then call the Validate method against the created validator instance.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 17, 2011 at 2:10 AM

I'm actually using Unity to do the following...

[Dependency] public Validator<ICustomer> { get; set; }

The code works against the base class...

[Dependency] public Validator<ICompany> { get; set; }

but not the descendent.

Thanks,

John

Jan 17, 2011 at 7:24 AM

What I meant was, where are your validators (NotNullValidator, StringLengthValidator, etc) applied on?  Keep in mind that in your case your Validator<ICustomer> won't take into consideration the validation rules defined in the ICompany interface and vice versa. 

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 17, 2011 at 12:57 PM

re: Keep in mind that in your case your Validator<ICustomer> won't take into consideration the validation rules defined in the ICompany interface and vice versa. 

Ah, ok, so this is a design decision?

If find that a very odd decision indeed. So odd in fact, that I would venture to guess it was simply an oversight, wouldn't you agree?

If not, would could possibly be the motivation behind it?

Jan 18, 2011 at 4:23 AM

I would think this is by design but unfortunately don't know the rationale behind this. EntLib team may be able to provide more information regarding this as well for the motivation on utilizing this. I'm trying to find related item logged same with this issue in the issue tracker but haven't found yet. Anyway, one thing you can do is to log an Issue on the issue tracker and vote on it.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com