Reputation: 8233
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.
public interface INorthwindContext
{
public IDomainContext Context;
}
I've tried using a partial class in my Silverlight project to implement an interface like so:
public partial class NorthwindContext : INorthwindContext
{
}
Now I can create a DataService or TestDataService etc, like so:
public class DataService : IDataService
{
public INorthwindContext Context { get; set; }
}
My INorthwindContext:
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.
public interface INorthwindContext
{
EntitySet<Category> Categories { get; }
EntityQuery<Category> GetCategoriesQuery();
EntityQuery<Product> GetProductsQuery();
EntityQuery<Region> GetRegionsQuery();
EntityQuery<Shipper> GetShippersQuery();
EntityQuery<Supplier> GetSuppliersQuery();
EntityQuery<Territory> GetTerritoriesQuery();
EntitySet<Product> Products { get; }
EntitySet<Region> Regions { get; }
EntitySet<Shipper> Shippers { get; }
EntitySet<Supplier> Suppliers { get; }
EntitySet<Territory> Territories { get; }
}
This was very helpful and http://www.nikhilk.net/NET-RIA-Services-ViewModel-Pattern-2.aspx
Upvotes: 1
Views: 713
Reputation: 2039
Here's the pattern I recommend for using RIA Services with MVVM (which is a good pattern to use for mocking and design-time data). It's a take on John Papa's MVVM sample.
Upvotes: 3