Adapter validator is not working - DI

Posts   
 
    
Khurram
User
Posts: 198
Joined: 26-Nov-2011
# Posted on: 07-Dec-2011 19:22:19   

Hi, I have a customer entiry and want to call my validations on entity before save, so what i have done is

  1. this is my config file
<section name="dependencyInjectionInformation" type="SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler, SD.LLBLGen.Pro.ORMSupportClasses.NET20, Version=3.1.0.0, Culture=neutral, PublicKeyToken=ca73b74ba4e3ff27"/>

<dependencyInjectionInformation>
        <additionalAssemblies>
            <assembly filename="MyProject.Data.Validation.Validators.dll"/>
        </additionalAssemblies>
</dependencyInjectionInformation>
  1. created a seperate project and added a class for validation below is the code for that class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SD.LLBLGen.Pro.ORMSupportClasses;
using MyProject.Data.DatabaseSpecific;
using MyProject.Data.EntityClasses;
using MyProject.Data.FactoryClasses;
using MyProject.Data.HelperClasses;
using MyProject.Data.Linq;
using MyProject.Data.RelationClasses;

namespace MyProject.Data.Validation.Validators
{
    [DependencyInjectionInfo(typeof(CustomerEntity), "Validator")]
    public class CustomerEntityValidator:ValidatorBase
    {
        public override void ValidateEntityBeforeSave(IEntityCore involvedEntity)
        {
            CustomerEntity entity = new CustomerEntity();

            if ((entity.FirstName == null) || (entity.FirstName == string.Empty))
            {
                throw new ORMEntityValidationException("First Name cant be null", entity);
            }
            base.ValidateEntityBeforeSave(involvedEntity);
        }

    }
}

Dont know when I am calling the save method of adapter its not coming into here, please help.

Thanks Khurram

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Dec-2011 03:39:18   

Check these points:

  1. If you are using a Web application you must use the fullname assembly as stayed in the Docs:

Docs wrote:

Auto-discovery doesn't work in website applications most of the time, so you should define Dependency Injection configuration settings in the web.config file as defined in the Manual discovery through dependencyInjectionInformation sections in the .config file below. You then also should specify the assemblies with the fullName attribute and the assembly's full name, instead of the file name like in the following example. Example:

<assembly fullName="MyAuditorAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>

This is necessary because the reference to the assembly with the Dependency Injection classes isn't there, as the pages are often compiled in separate assemblies. After deployment, it might be that the references are there, but that's not always the case. Better is to define this in the config file using the dependencyInjectionInformation section.

When the injectable types are defined inside the webapplication however, the auto-discovery works.

  1. Although this seems obvious, please double check that your validator assembly is reachable by your application. In other words, make sure you referenced the project in your app, or that the assembly is copied to the app's output bin folder.
David Elizondo | LLBLGen Support Team