I have looked at the examples for using DI for validation.
But when I test it, nothing happens.
If I use the protected override bool OnValidateFieldValue(int fieldIndex, object value)
method in a partial class for the entity I am using to validate it, it works.
I have created a Validator class library project with a single class in it
called Validate.data.Validators.
namespace Validate.Data.Validators
{
[DependencyInjectionInfo(typeof(PriorityEntity), "Validator")]
[Serializable]
public class PriorityValidator : ValidatorBase
{
public override bool ValidateFieldValue(IEntityCore involvedEntity, int fieldIndex, object value)
{
// value to return
bool fieldIsValid = true;
Debug.WriteLine("PriorityValidator ValidateFieldValue");
if (value != null)
{
switch ((PriorityFieldIndex)fieldIndex)
{
case PriorityFieldIndex.PoliceCaseType:
if (((int)value) > 3)
{
fieldIsValid = false;
involvedEntity.SetEntityFieldError(PriorityFieldIndex.PoliceCaseType.ToString(),
"Priority must be < 4", false);
}
break;
}
}
return fieldIsValid;
}
}
}
I build the class library and reference it in my main startup project.
Not sure if I should reference it but I do anyway.
In the app.config I specify
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- ENABLING DEPENDENCY INJECTION
For more info read "LLBLGenPro Help - Depedency Injection mechanism"-->
<section name="dependencyInjectionInformation" type="SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler, SD.LLBLGen.Pro.ORMSupportClasses.NET20, Version=2.6.0.0, Culture=neutral, PublicKeyToken=ca73b74ba4e3ff27"/>
</configSections>
<!-- SPECIFYING DI INFORMATION
Comment/Uncomment assemblies to enabled/disabled Auditors injected to your EntityClasses
For more info read "LLBLGenPro Help - Depedency Injection mechanism" -->
<dependencyInjectionInformation>
<additionalAssemblies>
<assembly filename="Validate.data.Validators.dll"/>
</additionalAssemblies>
</dependencyInjectionInformation>
<appSettings>
<add key="Main.ConnectionString" value="data source=pcp19006\wardendev;initial catalog=WardenII;integrated security=SSPI;persist security info=False;packet size=4096"/>
<!--<add key="buildInValidationBypassMode" value="0"/>-->
<add key="autoDependencyInjectionDiscovery" value="true"/>
</appSettings>
<system.diagnostics>
<switches>
<add name="SqlServerDQE" value="4" />
<add name="ORMGeneral" value="4" />
<add name="ORMStateManagement" value="4" />
<add name="ORMPersistenceExecution" value="4" />
</switches>
</system.diagnostics>
</configuration>
Nothing happens. No validation.
How can you debug this sort of thing? How do you tell if ones validator has been injected?
can you put breakpoints in your validation class?
If I need to access resources in other assemblies (I want to be able to validate using a spell checker) how does one gain access to these. I mean when the validator is contructed
I need to set some references to other objects. Or set a reference in other objects to the instantiated validator class.
Does that make sense?