Silverlight RIA Custom Validation: Circular Reference, Help!

Posts   
 
    
ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 17-Dec-2011 11:44:36   

Hello,

Thank you for reading my posting. We have a Silverlight 4 RIA application that uses LLBLGEN for its data access layer. My question is not directly about LLBLGEN, but I hope that another forum member of LLBLGEN may have encountered this problem and may have some advice.

We've implemented a custom RIA validator to ensure that a customer's name is not duplicated in the Customers table. Our implementation is based on Jeff Handley's posting at http://jeffhandley.com/archive/2010/05/26/asyncvalidation-again.aspx. Everything was going well and compiled until I added the custom validator to our CustomerEntity. Now, the CustomerEntity will not compile because the custom validator is undefined. I understand why it is complaining, but I am totally lost as to how to fix it. I hope that someone can help be find my way again!

Here are the relevant references between the projects in our our solution:

CLIENT (Silverlight) - customervalidator.shared.cs (via shared mechanism)

WEB (Server) | - customervalidator.shared.cs exists here. | - mydomainservice.cs exists here. It contains the IsCustomerNameAvailable custom validator method. | | (references) | v DAL (LLBLGEN data access layer, contains our model entities) - CustomerEntity.cs contains our RIA custom validator tag the on the Customer.Name field. [CustomValidation(typeof(CustomerNameValidator), "IsCustomerNameAvailable")]


ISSUE: The custom validator is available on the CLIENT and WEB (server), but the entity code in the DAL has no access to it. If I could add a reference from the DAL to the WEB project, a circular reference would result. So, I am at a loss how to fix it... I would truly appreciate your comments about how to correct my situation. I found a few people with similar postings, but, alas, no responses...

Thank you for your time and interest, Mike

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 17-Dec-2011 11:56:07   

In general you fix this by defining an interface. The interface is defined in a 3rd project. Both projects which would use your validator, are programmed against the interface (so directly reference the 3rd project, not your validator class!). The validator class implements the interface, and at runtime you instantiate an instance of that validator through a factory in the 3rd project (the one with the interface). This way your projects don't reference the validator but the 3rd project. The 3rd project references the validator project and creates instances for the validator. Not sure if this is usable in your project, but it's in general how you'd solve this.

Frans Bouma | Lead developer LLBLGen Pro
ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 18-Dec-2011 01:46:42   

Hi Otis,

Thank you very much for your detailed reponse! I will try to adapt it to our solution and see how things work out. Thank you again for your help!

Have a great holiday season!

Mike

ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 19-Dec-2011 04:10:28   

Hi Otis,

Well, I spent most of the day trying to resolve my issue with RIA async validation, but without success. I tried to implement the pattern that you described but hit two problems: Cannot use a factory method and had issues with static access. I tried adding the customervalidator.shared.cs in the Web project to the DAL as a link, but then I had to pull in my domain data source and it became very messy very quickly. I thought about adding validation within the CustomerEntity itself, since it can access the database, but the Client complained about not having access to the validator. When I tried to link to the DAL, of course, the Client complained about the DAL not being a Silverlight project. Argggg... Pretty frustrating day! simple_smile

Given so many people are creating Silverlight applications with async validation and a DAL layer, I am shocked that there are hardly any postings about the issue that I have encountered. It makes me think that either no one is using async validation (yeah, right), or has figured it out and did not feel the need to publish the solution, or I am making things more difficult than they are. I cannot see how I am making it difficult since the references are quite straight forward.

I know that this is not an issue with LLBLGEN, but in the interest of helping other Silverlight developers, I hope that we can keep discussing this issue so a solution will be available to others... as welll as myself! stuck_out_tongue_winking_eye Anyway, I'd love to hear more suggestions when you have a free moment.

Thank you again for your help and interest,

Mike

ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 28-Dec-2011 05:23:42   

Well, I've resolved this issue, but I must admit that it is not the elegant solution that I hoped for... I was hoping that I could move the LLBLGEN DAL and my domain data source code into a Portable Project Library, but at this time, it does not permit the necessary .NET references in order to work. In case another user has this issue, here is what I've done:

1) Removed the two LLBLGEN projects from our solution;

2) Moved the DatabaseGeneric and DatabaseSpecific folders to a DAL folder in our Web project folder;

3) I've loaded the existing items in those two folders into our Web project;

4) I've excluded the bin folders, Assembly.cs files, and app.config file from the Web project;

5) I've made sure the the usual four SD references (SD.LLBLGen.Pro.DQE.SqlServer.NET20, SD.LLBLGen.Pro.LinqSupportClasses.NET35, SD.LLBLGen.Pro.ORMSupportClasses.NET20, SD.LLBLGen.Pro.RiaSupportClasses) are in the Web project's references. They were already there due to our domain data source code.

Now, everything works...

Mike