WCF 与 ASP.NET MVC - 参考项目
在 ASP.NET MVC 项目中,数据访问层将在 WCF 中实现。原因是这些 WCF 服务将来将被其他几个客户端应用程序使用。
不知道有没有什么好的参考项目可以看一下。 我需要了解的重要事项是:
- 项目的结构如何
- 需要遵循的最佳实践 域
- 对象/POCO、DTO、ViewModel 需要如何组织并相互通信
- 单元测试方法
非常感谢您在这些领域的所有建议/建议
非常感谢。
on a ASP.NET MVC project, the data access layer is going to be implemented in WCF. Reason is that these WCF services are going to be consumed by couple of other client applications in the future.
Can I know whether there are any good reference projects that I can have a look at.
Important things that I need to have a look at are:
- How the projects are structured
- Any best practices that need to be followed
- How Domain objects/POCOs, DTOs, ViewModels need to be organized, and communicate between each other
- Unit Testing approaches
All your suggestions/advices on these areas are highly appreciated
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将执行与执行任何其他 ASP.NET MVC 应用程序完全相同的操作。您只需提供存储库的一个实现,该实现将调用 WCF 服务。因此,基本上,您的存储库接口可能是您导入服务时获得的操作契约:
Product
和IProductsService
是来自 WCF 服务的域对象。在此接口的实现中,您可以将调用委托给服务本身。就应用程序的其余部分而言,您的控制器并不真正关心,因为它们是弱耦合的:非常标准的东西,无论数据来自哪里,您的控制器都应该是什么样子。正如您所看到的,如果您总是使用抽象来设计应用程序,您可以非常轻松地切换此
IProductsService
的实现,该实现将被注入到您的控制器中,并且从 ASP.NET MVC 应用程序的角度来看,它甚至不会任何差异。视图模型应该是 Web UI 的一部分,因为它们与视图紧密相关。服务契约和领域模型进入服务层。
You would do exactly the same as if you were doing any other ASP.NET MVC application. You would simply provide an implementation of your repository which would call the WCF service. So basically your repository interface could be the operation contract you got when you imported your service:
Product
andIProductsService
are domain objects coming from your WCF service. In the implementation of this interface you would delegate the call to the service itself. As far as the rest of the application is concerned, your controllers doesn't really care as they are weakly coupled:Pretty standard stuff and it is how your controllers should look like no matter where the data comes from. As you can see if you always design your applications with abstractions you could very easily switch implementation of this
IProductsService
that will be injected into your controllers and from the ASP.NET MVC application standpoint it wouldn't even make any difference. The view models should be part of the web UI as they are strongly tied to the views.The service contracts and domain models go into a service layer.