Property Validation with Policy Injection

Topics: Policy Injection Application Block, Validation Application Block
Jun 6, 2007 at 11:01 PM
Hi,

I like to have a property validation called from Policy Injection. So everitime the property is set the Policy Injection should validate the value.

First of all I have a small Interfaces with the property and also a interface methode.
Interface
interface ITestObject
{
RangeValidator(50, RangeBoundaryType.Exclusive, 100, RangeBoundaryType.Inclusive, MessageTemplate = "Value Range error")
int Value
{
get;
set;
}

ValidationCallHandler
List<TestDataContract> FindData(TestDataContract request);
}

The configucation looks
<add name="Policy">
<matchingRules>
<add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.TypeMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=3.1.0.0, Culture=neutral, PublicKeyToken=5a467f8f18a3a234"
name="Type Matching Rule">
<matches>
<add match="HowTo.ITestObject" ignoreCase="false" />
</matches>
</add>
</matchingRules>
<handlers>
<add ruleSet="" specificationSource="Both" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.ValidationCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers, Version=3.1.0.0, Culture=neutral, PublicKeyToken=5a467f8f18a3a234"
name="Validation Handler" />
</handlers>
</add>

And the program looks
ITestObject woObj1 = PolicyInjection.Wrap<ITestObject>(obj1);
woObj1.Value = 500;
with this assignment nothing is happen (but I expect a exception)
woObj1.FindData(new TestDataContract("123456", "12"));
this FindDate will throw a exception (this is what I expact)
ValidationResults vr2 = Validation.ValidateFromAttributes<ITestObject>(woObj1);
The Valudation Result is correct filled

Should this work? I make a mistake or is this a bug?

Thanks
Ralf