简体   繁体   English

通过SOAP的MVC 3存储库模式

[英]MVC 3 Repository Pattern via SOAP

appreciate any help with this. 感谢对此的任何帮助。

We are currently working on remodelling a legacy project that is now heading towards being too much of a nightmare to maintain. 我们目前正在努力改造一个遗留项目,该项目现在正面临着太多的噩梦,难以维护。 So, we've decided to properly normalise the data structure and use Entity Framework 4 Code First development in an MVC 3 project using a repository pattern. 因此,我们决定适当地规范化数据结构,并使用存储库模式在MVC 3项目中使用Entity Framework 4 Code First开发。 The issue we face at the moment is that the legacy application is hosted on a server outside of our main infrastructure for security reasons - therefore all CRUD operations are done via web services, there is no direct connection string to the MS SQL database. 当前,我们面临的问题是,出于安全原因,旧版应用程序托管在我们主要基础架构之外的服务器上-因此,所有CRUD操作都是通过Web服务完成的,没有与MS SQL数据库的直接连接字符串。

My "proposed" solution is to define my repository contracts, during development there will be a direct connection to the database but once deployed there won't be (there may be scope to getting that changed later). 我的“建议”解决方案是定义我的存储库合同,在开发过程中将直接连接到数据库,但是一旦部署就不会存在(以后可能会有更改的范围)。 So, would it be reasonable for me to provide two concrete versions of the repository working to the same contract. 因此,对我而言,提供适用于同一合同的两个具体版本的存储库对我来说是否合理? One that uses LINQ to perform CRUD operations (development and possible the infrastructure we can move to later) and another version that uses SOAP to pass objects (that would mean my POCOs would need to be defined as Serializable) and perform the CRUD operations this way? 一个使用LINQ来执行CRUD操作(开发和可能的基础设施,我们可以稍后再使用),另一个使用SOAP来传递对象的版本(这意味着我的POCO需要定义为Serializable)并以这种方式执行CRUD操作?

Does this sound feasible or is there a much better way of achieving this? 这听起来可行吗,还是有更好的方法来实现呢?

Thanks! 谢谢!

If you are responsible for developing both client and service part you can use some simple approach: 如果您负责开发客户端和服务部分,则可以使用一些简单的方法:

  • Use some shared interface for repository and service client 对存储库和服务客户​​端使用一些共享接口
  • When working with remote repository in client inject service client - the service will use repository implementation directly 在客户端注入服务客户端中使用远程存储库时,该服务将直接使用存储库实现
  • When working with local repository in client inject repository directly 在客户端直接注入存储库中使用本地存储库时

By using this approach you will have single repository implementation for both scenarios and your upper level logic will not change. 通过使用这种方法,您将在两种情况下都具有单一的存储库实现,并且上层逻辑不会更改。 There will be only additional web service layer for remote repository. 远程存储库将只有附加的Web服务层。 Your repository will have to encapsulate all data access logic and queries = no linq queries outside of the repository which is not the issue in your architecture because linq queries are not serializable without your own custom development or without using WCF Data Services (but it would have other impacts on your architecture). 您的存储库将必须封装所有数据访问逻辑和查询=在存储库之外没有linq查询,这在您的体系结构中不是问题,因为如果没有您自己的自定义开发或使用WCF数据服务,则linq查询是不可序列化的(但是对架构的其他影响)。

Btw. 顺便说一句。 it is not very common to place repository behind the web service. 将存储库放在Web服务后面不是很常见。 More common is to place whole service layre / business logic behind the web service. 更常见的是将整个服务行业/业务逻辑置于Web服务之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM