title: Interface a DomainContext for WCF RIA Services - is this a good approach?
body: <p>I want to have an IDataService that I can then swap out with a different service for mocking or use for Design time data. Is this a good approach or am I just creating problems for myself.</p>
  
  <pre><code>public interface INorthwindContext
  {
    public IDomainContext Context;
  }
  </code></pre>
  
  <p>I've tried using a partial class in my Silverlight project to implement an interface like so:</p>
  
  <pre><code> public partial class NorthwindContext : INorthwindContext
     {
     }
  </code></pre>
  
  <p>Now I can create a DataService or TestDataService etc, like so:</p>
  
  <pre><code>public class DataService : IDataService
  {
      public INorthwindContext Context { get; set; }
  }
  </code></pre>
  
  <p>My INorthwindContext:</p>
  
  <p>EDIT: unless I add all the methods from the DomaincContext to this interface I'm going to lose need functionality to lad the data. I'm also going to have to manually update the interface each time I add new entites to the service.</p>
  
  <pre><code>public interface INorthwindContext
     {
        EntitySet&lt;Category&gt; Categories { get; }
        EntityQuery&lt;Category&gt; GetCategoriesQuery();
        EntityQuery&lt;Product&gt; GetProductsQuery();
        EntityQuery&lt;Region&gt; GetRegionsQuery();
        EntityQuery&lt;Shipper&gt; GetShippersQuery();
        EntityQuery&lt;Supplier&gt; GetSuppliersQuery();
        EntityQuery&lt;Territory&gt; GetTerritoriesQuery();
        EntitySet&lt;Product&gt; Products { get; }
        EntitySet&lt;Region&gt; Regions { get; }
        EntitySet&lt;Shipper&gt; Shippers { get; }
        EntitySet&lt;Supplier&gt; Suppliers { get; }
        EntitySet&lt;Territory&gt; Territories { get; }
     }
  </code></pre>
  
  <p><a href="http://forums.silverlight.net/p/183791/483180.aspx" rel="nofollow">This was very helpful</a> and <a href="http://www.nikhilk.net/NET-RIA-Services-ViewModel-Pattern-2.aspx" rel="nofollow">http://www.nikhilk.net/NET-RIA-Services-ViewModel-Pattern-2.aspx</a></p>