为 WCF RIA 服务连接 DomainContext - 这是一个好方法吗?
我想要一个 IDataService,然后我可以将其替换为其他服务以进行模拟或用于设计时数据。这是一个好方法还是我只是给自己制造问题。
public interface INorthwindContext
{
public IDomainContext Context;
}
我尝试在我的 Silverlight 项目中使用分部类来实现如下接口:
public partial class NorthwindContext : INorthwindContext
{
}
现在我可以创建 DataService 或 TestDataService 等,如下所示:
public class DataService : IDataService
{
public INorthwindContext Context { get; set; }
}
我的 INorthwindContext:
编辑:除非我将 DomaincContext 中的所有方法添加到此接口将失去获取数据所需的功能。每次向服务添加新实体时,我还必须手动更新界面。
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; }
}
这非常有帮助和http://www.nikhilk.net/NET-RIA-Services-ViewModel-Pattern-2.aspx
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我推荐的模式 将 RIA 服务与 MVVM 结合使用(这是用于模拟和设计时数据的良好模式)。这是 John Papa 的 MVVM 示例的一个版本。
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.