views:

574

answers:

1

In .NET RIA Services you can write code on the server with a suffix of .shared.cs or .shared.vb and it will be available for you on the client.

My question is why would I want this?

Assuming that I use a DomainModel with proper business objects and a ViewModel wouldn't all the code I would need reside in those classes? This looks like global code that can be a potential dumping ground because the developer didn't design properly and now has a bunch of classes in shared code which probably belongs in the business layer or the UI Layer.

Am I right in thinking this or am I missing something fundamental?

+4  A: 

Here are some scenarios for shared code:

  1. Computed properties that are common on server and client. Say I want to add an ImageUrl property on my Product class that is a function of the product's ID, and use that property on the server and on the client.

  2. Shared validation code. Using the same product class, say I had a validation rule that a product's description property must be a paragraph of text. I could write that rule once, and attach it to product or its description property, and making it shared allows me to validate on client as well as server.

  3. Utility classes are just as interesting. I might have a utility class that does the computation or is referenced by a validation rule etc.

Hope that helps.

NikhilK