Design Question (Validation)

Design Question (Validation)

Old forum URL: forums.lhotka.net/forums/t/10742.aspx


MadGerbil posted on Thursday, October 06, 2011

I've a collection that I show in a datagrid using Silverlight.

Let's say the collection is an Address collection and I've 3 columns that need to be validated: City, State, ZipCode.   Each of these columns needs to validate against a list.   Those lists are in tables in my database.   What is the best way to load up those lists so that I may write business rules against them.

Don't get distracted by the example.  Obviously, the State list is a well known list that isn't likely to change anytime soon so one would likely put that in a combobox and be done with it; however, this is only an example of the problem - for the sake of this example assume the State list changes frequently.

So here are my thoughts:

1: I could load up the 3 lists on each Address object.   On the plus side, the rule code is easy to write and the object is self-contained.  On the down side it really bloats the object graph, needlessly repeating collections that will be the same across all objects.

2: I could load up the 3 lists into a static field on the Address object.  This would cut down on the bloat but I don't know if it's the correct way to handle this thing.  Is serialization a problem here?  I dunno.

3: The lists could be on the AddressList collection object.  I could reference those lists in the rules by using the Address object's parent.  

4: I could use asynchronous rules to query the database when an item needs to be validated.  This seems unnecessary (only one user is likely to be using this part of the overall system so I don't have concurrency concerns) and I don't know if I want a *busy* indicator coming up every time a record is edited. 

Thoughts?

JonnyBee replied on Thursday, October 06, 2011

Hi,

Another option is to let the actual lists "cache" themselves, in the same way as NameValueLists do and also provide a way of "ClearCache" so that when the "editable object" of the items in the list is changed you can also clear the list (especially as this is a single user application).

Your BO and Rules would just fetch the list as usual (only the list class will know if it is already fetched or if it needs to access the database).

In a multi-user system I would prefer option 4 and do a check with the actual data in the database.

 

 

MadGerbil replied on Thursday, October 06, 2011

The cache approach is probably the best fit for my application. Is there a sample of that somewhere?

JonnyBee replied on Thursday, October 06, 2011

Look at ProductCategory class in InventoryDemo project in Silverlight samples.

Copyright (c) Marimer LLC