.NET RIA Services allows you to write code on the server in an ASP.NET project, and have it available within a Silverlight application hosted by that web project.  Using build-time code generation, your entity types in the server project become available within the client project.  You can get .NET RIA Services today and provide feedback on the forums.

Well, I am working on a scenario where I needed to have an entity implement a custom interface on both the server and the client.  I immediately wondered, “How on Earth will the code generation know to propagate my interface implementation to the client?”  I started digging into the code gen and found that it doesn’t do anything with regard to interface implementations.  I briefly thought that code gen would have to be augmented to allow my scenario.  Let’s break down what would need to happen:

  1. How would code generation know which interfaces to propagate?  It might need to have some sort of allow list for interfaces that should be propagated.
  2. How would it get the actual implementation over into the client?  You’d need some way of marking the implementation methods as shared so they move over.

Oh wait, “shared;” duh!  It hit me that we already have a solution for this.  All you have to do is use a partial class for your model, and name the file with .shared.cs (or .shared.vb).  This file will automatically be copied to the Silverlight project, so whatever is in it will be retained on the client.  So with all of the interface implementation in that file, you’re done.  That was easy!


   1: public partial class MyEntity : IMyCustomInterface
   2: {
   3:     public void MyCustomInterfaceImplementation() { ... }
   4: }
Technorati Tags: ,