Hi,
I've been trying to get XAF validation rules to work in a non-XAF application for a while but still don't know if it's possible or not. I've been reading a lot along the support tickets but still can't get a clear idea of it. Can you help me please?
My scenario is this:
- I have a big application with lots of validation rules for the entities
- I have recently created a non-XAF application to perform background and massive operations to tha data in the application
- that validation rules are not working in that new application, I mean no exception is thrown when a rule is not correct for any object
- UnitsOfWork are being used in that application, is it correct?
Here's how UnitOfWorks are created in the non-XAF application:
C#string lConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
System.Reflection.Assembly[] assemblies = new System.Reflection.Assembly[] {
typeof(Adreca).Assembly, //DivisionsTerritorials
typeof(frsdMessage).Assembly, //ExpressApp.Messaging
typeof(CuentaBancaria).Assembly }; //PersistentBase
foreach (System.Reflection.Assembly lAssembly in assemblies)
{
foreach (Type type in lAssembly.GetExportedTypes())
{
XafTypesInfo.Instance.RegisterEntity(type);
Validator.RuleSet.RegisterRules(XafTypesInfo.Instance.FindTypeInfo(type));
}
}
foreach (Type type in typeof(Module.Empresas.Empresa).Assembly.GetExportedTypes())
{
XafTypesInfo.Instance.RegisterEntity(type);
Validator.RuleSet.RegisterRules(XafTypesInfo.Instance.FindTypeInfo(type));
}
XafTypesInfo.Instance.GenerateEntities();
DevExpress.Xpo.Metadata.XPDictionary lDict = new DevExpress.Xpo.Metadata.ReflectionDictionary();
lDict.GetDataStoreSchema(typeof(Module.Empresas.Empresa).Assembly);
DevExpress.Xpo.XpoDefault.Session = null;
IDataStore lStore = DevExpress.Xpo.XpoDefault.GetConnectionProvider(lConnectionString, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists);
IDataLayer dl = new DevExpress.Xpo.ThreadSafeDataLayer(lDict, lStore);
lUnit = new UnitOfWork(dl);
XPObjectSpace objectSpace = new XPObjectSpace(
XafTypesInfo.Instance,
XpoTypesInfoHelper.GetXpoTypeInfoSource(),
new CreateUnitOfWorkHandler(() => { return lUnit; }));
But when a CommitChanges() is called validation rules are not applied. Is there something missing?
Otherwise if I try to force rules validation using this code inside an OnSaving method
C#IObjectSpace lObjSpace = DevExpress.ExpressApp.Xpo.XPObjectSpace.FindObjectSpaceByObject(this);
if (lObjSpace != null) Validator.RuleSet.Validate(lObjSpace, this, DefaultContexts.Save);
An exeption is thrown saying that the entity trying to be validate "is not registered".
Due to that we are now having inconsistent objects in the database, can you help us please?
Thanks,