Validator not loading using Dependency Injection

Posts   
 
    
rblasutig
User
Posts: 11
Joined: 22-Feb-2008
# Posted on: 15-Oct-2008 02:35:03   

I have a validator defined in my BSL assembly. This references my DAL assembly. Using dependency injection, this validator will not get executed on save. If I create a new assembly, which has its own reference to the DAL, DI happens perfectly.

Can anyone guess as to a reason why this doesn't work? I'd like to be able to explain it rather than giving up on it.

I'm using v2.6 with adapter as a web application.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Oct-2008 03:01:32   

Must be something on the DI discovery stuff. Please post your web.config where you are setting DI settings.

David Elizondo | LLBLGen Support Team
rblasutig
User
Posts: 11
Joined: 22-Feb-2008
# Posted on: 15-Oct-2008 03:17:10   

<dependencyInjectionInformation>
    <additionalAssemblies>
        <assembly filename="CSRS.Validation.dll"/>
    </additionalAssemblies>
    <additionalAssemblies>
        <assembly fullName="CSRS.Evolution.PPSA.BSL, Version=1.0.0.0"/>
    </additionalAssemblies>
</dependencyInjectionInformation>

The first assembly works, the second does not. I have also tried using: filename="CSRS.Evolution.PPSA.BSL.dll" which was also not successful.

The assembly names from Visual Studio are CSRS.Validation and CSRS.Evolution.PPSA.BSL.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Oct-2008 05:49:57   

What if you try this?

<assembly fullName="CSRS.Evolution.PPSA.BSL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
David Elizondo | LLBLGen Support Team
rblasutig
User
Posts: 11
Joined: 22-Feb-2008
# Posted on: 23-Oct-2008 01:55:51   

Sorry to take so long to respond. Okay, I gave this format a try. I needed to specify a public key token, as the assembly is signed. After that, my app again starts correctly. That confirms that the assembly is being loaded. But it still won't call the validator.

I need to find more information for you (my info thus far is pretty useless), there is something specific about that assembly that may be causing a problem.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 23-Oct-2008 11:53:20   

Would you please post the DependencyInjectionInfo attribute used for the Validator?

rblasutig
User
Posts: 11
Joined: 22-Feb-2008
# Posted on: 23-Oct-2008 18:37:01   
[DependencyInjectionInfo(typeof(RegistrationEntity), "Validator")]
[Serializable]
public class RegistrationValidator : ValidatorBase

I have the same attribute defined for the class regardless of the assembly I put it in.

jackbauer
User
Posts: 12
Joined: 08-Oct-2008
# Posted on: 24-Oct-2008 05:08:37   

Hi Everybody! I have the same problem, but i explaind a little more my demoApp

-Solution DemoApp -DAL Project -WebSite -AppValidators this is the Web.Config


    <configSections>
        <section name="dependencyInjectionInformation" type="SD.LLBLGen.Pro.ORMSupportClasses.DependencyInjectionSectionHandler, SD.LLBLGen.Pro.ORMSupportClasses.NET20, Version=2.6.0.0, Culture=neutral, PublicKeyToken=ca73b74ba4e3ff27"/>
    </configSections>
    <dependencyInjectionInformation>
        <additionalAssemblies>
            <assembly filename="AppValidators.dll"/>
        </additionalAssemblies>
    </dependencyInjectionInformation>

I don't know why the validation don't work.

Thanks in advanced

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Oct-2008 06:12:42   

I can't reproduce that problems. For you guys, please follow these steps:

  1. Double check that the dll containing the validator classes is actually copied to the output bin folder. This means that you have to reference the assembly (or project) at your GUI project.

  2. Make sure you have properly configured the DI. Typically this will looks like this:

<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="SD.LLBLGen.Pro.Examples.Validation.Validators.dll"/>
    </additionalAssemblies>
</dependencyInjectionInformation>
  1. Make sure your validator is configured to inject itself to the properly entities. This typically will looks like:
[DependencyInjectionInfo(typeof(OrderEntity), "Validator")]
[Serializable]
public class OrderValidator : ValidatorBase
{
   ...
}
  1. Make sure the problem is about Dependency Injection and not on your ValidatorClass. For example, test you validator assigning it directly (without DI).

  2. If you tried all above and you are at the same place. Please open a HelpDesk-Forum thread and attach some repro solution so we can identify the specific problem.

David Elizondo | LLBLGen Support Team
jackbauer
User
Posts: 12
Joined: 08-Oct-2008
# Posted on: 24-Oct-2008 20:03:01   

Hi Daelmo,

Thanks for the quick answer, i have one more question, sorry for bother you.

The namespaces in the DAL and the Validator have to be the same?

Like this:

DAL.EntityClasses

and in the validator

DAL.Validators.

Thanks in advance!

Adding more information I'm using selfservicing, latest version of LLBL. On a WebSite, not a Web Application.

Im really stuck with this, none of the validation execute.

PD: sorry for my bad english

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Oct-2008 06:08:32   

jackbauer wrote:

Thanks for the quick answer, i have one more question, sorry for bother you.

No worries. We are happy to help you.

jackbauer wrote:

The namespaces in the DAL and the Validator have to be the same?

No, they don't have to be at the same root. Just be sure that the entities that will be injected are reacheable from your validator (correct using namespaces).

jackbauer wrote:

Adding more information I'm using selfservicing, latest version of LLBL. On a WebSite, not a Web Application.

Im really stuck with this, none of the validation execute.

I'll do a test with that info to see if I can repro your problem.

David Elizondo | LLBLGen Support Team
jackbauer
User
Posts: 12
Joined: 08-Oct-2008
# Posted on: 25-Oct-2008 22:34:01   

Hi Daelmo,

After almost bust my head over the wall i could make the validator works, so thank for the patient and answer all the question!

But now i have one more. (yes i know im very annoying, sorry rage )

I using the validation example in the LLBLGEN web site, the web Application one, with Adapter to see how the validation works and then make my own application.

In that example the Customer have several Field Validations, but when i try no insert a new Customer the Regular Expression Validator caught the error and show the msg error. But what happen if the user bypass the javascript validation. I try that and the Validator in the "ValidateFieldValue" execute perfectly but. That all, nothing happen and then when is trying to insert show the exception from SQL Server that is no the same in the method "ShowEntityErrors" so i got the green page error.

How i can show the field errors?

Thanks in advance! You Rock Daelmo!!!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Oct-2008 21:10:32   

We are working in some little changes on that Validation Example. I'll take your suggestion into account to test that scenario. I hope the new example will be released on Monday or Tuesday. I'll let you know here wink

(Edit) The Customer.aspx example is intended to demostrate the client-side validation plus validation of a Delete action. If you want to show the errors set on the entity fields you should implement something like the Product.aspx example.

protected void ProductsDS_EntityUpdating(object sender, CancelableDataSourceActionEventArgs e)
{
    // the entity involved
    ProductEntity entityToEvaluate = (ProductEntity)e.InvolvedEntity;

    // Retrieve the fields errors from the entity. This will return a semicolon-separated list containing the info.
    string errors = entityToEvaluate.GetEntityFieldsErrors();

    // there are errors, so cancel the update so the user can fix them.
    if (errors != string.Empty)
    {
        e.Cancel = true;
        ShowEntityErrors(errors);
    }
    else
    {
        HideEntityErrorControls();
    }
}

and see the _GetEntityFieldsErrors _method of the ProductEntity.

The thing is that we are showing the errors from the aspx validators, so we can't show the errors twice. What you also can do is check if the entity has errors (through the _GetEntityFieldsErrors _method) at the ValidateEntityBeforeSave. So if the entity has errors, throw an ORMValidationException.

Whether throw or not throw an exception on entity fields errors is up to you. Some people don't consider that a reason for not to save the entity: just some values are incorrect and that values wont be saved.

David Elizondo | LLBLGen Support Team
jackbauer
User
Posts: 12
Joined: 08-Oct-2008
# Posted on: 27-Oct-2008 02:45:14   

Hi Daelmo! Thanks a Lot!!! Im will waiting for the new example. Im really new using the product and so far is great, but the validation is my problem right now.

Again Thanks a Lot!!!!

(Edit) When i was writing this, you post the new example. man your awesome!!! Thank you VERY VERY MUCH!!!

jackbauer
User
Posts: 12
Joined: 08-Oct-2008
# Posted on: 27-Oct-2008 03:42:28   

I promise this will be the last question, I Hope!

The method GetEntityFieldsErrors do i have to write my self or is generated by LLBL? Because i don't have this method in my generated code. Maybe is a stupid question but sorry in advance confused

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-Oct-2008 10:41:03   

David wrote:

and see the GetEntityFieldsErrors method of the ProductEntity

This is not a generated method, but was manually implemented in the Validation example posted on the llblgen.com in the download section. Here is the implementation.

/// <summary>
/// Gets the entity fields errors.
/// </summary>
/// <returns>A separater-by-semicolon errors in string representation of the 
/// error (if exist).
/// This could be useful if you want to obtain the errors list at some GUI.</returns>
public string GetEntityFieldsErrors()
{
    // variables to construct the message
    StringBuilder sbErrors = new StringBuilder();
    string toReturn = string.Empty;

    // iterate over fields and get their errorInfo
    foreach (IEntityField2 field in this.Fields)
    {
        /// IEntity2 implements IDataErrorInfo, and it contains a collections of field errors already set. 
        /// For more info read the docs (LLBLGen Pro Help -> Using generated code -> Validation per field or per entity -> IDataErrorInfo implementation).
        if (!string.IsNullOrEmpty(((System.ComponentModel.IDataErrorInfo)this)[field.Name]))
        {
            sbErrors.Append(((System.ComponentModel.IDataErrorInfo)this)[field.Name] + DELIMITER);                  
        }
    }

    // determine if there was errors and cut off the extra ';'
    if (sbErrors.ToString() != string.Empty)
    {
        toReturn = sbErrors.ToString();
        toReturn = toReturn.Substring(0, toReturn.Length - 2);
    }

    return toReturn;
}