Silverlight validation with configuration file and attributes.

Topics: Silverlight Integration Pack, Validation Application Block
Jul 27, 2011 at 7:31 PM

I am trying to use configuration file based validation and having an issue where I call validate on my validator that was created from the ValidationFactory. The issue is that the config validation is not being applied and only see results from the DataAnnotation Attribute validation. In the Developers Guide ( Creating a Type Validator using the ValidationFactory reads "This validator will validate objects using a rule set, and/or any attributes and self-validation methods the target object contains." To me this implies that my config, attributes, and/or self-validation will be called.

How can I get validation results that use the configuration file rule set along with DataAnnotations Attributes?

Jul 28, 2011 at 8:42 AM


I believe this should be working. Can you post your relevant code so that we can reproduce it in our side?


Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Jul 31, 2011 at 7:56 PM
Edited Aug 1, 2011 at 1:03 AM

I figured out my issue, EnterpriseLibraryContainer.ConfigureContainer(...) does not set EnterpriseLibraryContainer.Current. When I was using the ValidationFactory<T> and PropertyValidationFactory, these methods were creating a new UnityContainer and thus my configuration was not present. In my UnityBootstrapper I set EnterpriseLibraryContainer.Current and the factories work as expected.

This is the code for loading and configuring validation with an existing container. 

var streamInfo = Application.GetResourceStream(new Uri("Validation.xaml"UriKind.Relative));
var streamReader = new StreamReader(streamInfo.Stream);
var configDictionary = (IDictionary)XamlReader.Load(streamReader.ReadToEnd());
var configSource = DictionaryConfigurationSource.FromDictionary(configDictionary);
var containerConfigurator = new UnityContainerConfigurator(this.UnityContainer);

Should EnterpriseLibraryContainer.ConfigureContainer set the Current container for me?
Does the Developers Guide have guidance on using an existing container?
Aug 2, 2011 at 9:24 AM

I believe you still need to set that thru code:

EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);


Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us