Async ValidationRule and updating the business Object

Async ValidationRule and updating the business Object

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


cds posted on Monday, August 10, 2009

Hi Rocky, et al.

I have a requirement in a Silverlight app (using 3.7.0) that the user can type a code into one field and, if another field is blank, it goes an looks up a value from the code in the first field. For example, the user is entering a new patient record and they type the GP code. This causes a lookup of a related Health Authority.

I thought about (and tried) doing this using an Async Rule - and got as far as getting the data back, then ran into the problem of not being able to update the actual business object as there is no "target" reference.

I've seen other posts relating to race conditions, and understand why it's ill-advised. But it's a real requirement for me.

In the end, I've overridden the PropertyHasChanged method on my business object to look for the specific property changing, then I fire off an async lookup which, when it returns, sets the field on the business object.

Is there a better way than this?

Cheers...

Craig

RockfordLhotka replied on Tuesday, August 11, 2009

That was a conscious design choice on our part to avoid a number of threading complexity issues.

It does lead to the limitation that async rules are validation only.

This is an area I'd like to improve at some point, to allow rules that modify the object. Almost certainly this will entail writing the rule as a multi-part method - the part that runs on the server, and the part that runs on the client's UI thread after the call returns from the server.

But that's not the current model, and your solution is a perfectly valid one.

Copyright (c) Marimer LLC