简体   繁体   English

Windows和Web应用程序C#asp.net之间的并发

[英]Concurrency between windows and Web app C# asp.net

I am wondering if there is a best practice in regards to concurrency between asp.net and a windows app using the same db? 我想知道在asp.net和使用同一数据库的Windows应用程序之间的并发方面是否存在最佳实践? I have a db with items their quantity, any of these items can be sold with different quantities from a website shopping cart or store location. 我有一个数据库,其中包含项目的数量,这些项目中的任何一个都可以从网站购物车或商店位置以不同数量出售。 updating the item quantity when user adds the item to their shopping cart seems to be a problematic approach. 当用户将商品添加到购物车中时更新商品数量似乎是一个有问题的方法。

Thanks 谢谢

I would suggest introducing a Gateway into your system. 我建议将网关引入您的系统。 The Gateway would be a single application (or part of one of your existing applications: the winforms app or the web app) that acts as the intermediary to the DB for both the windows app and the web app. 网关将是单个应用程序(或您现有应用程序之一的一部分:winforms应用程序或Web应用程序),同时充当Windows应用程序和Web应用程序的数据库中介。 This way, you only have one point of failure between db requests and the db itself. 这样,您在数据库请求和数据库本身之间只有一个故障点。 Design that Gateway to manage concurrency and then you dont have to worry about other processes writing to your db. 设计该网关来管理并发性,那么您不必担心其他进程将数据写入数据库。

If i was in your position i might select the web app to be the gateway. 如果我在您的位置,则可以选择Web应用程序作为网关。 Create a set of services/repositories to interface with the db and have the UI layer of the web app access those services. 创建一组服务/存储库以与db进行接口,并使Web应用程序的UI层访问这些服务。 Then expose those services via web services (or WCF services) to your windows app for it to access the db instead of it accessing the db directly. 然后通过Web服务(或WCF服务)向Windows应用程序公开这些服务,以使其访问数据库,而不是直接访问数据库。 This way you have decoupled your system and created a single point of entry to the data store. 这样,您就可以将系统解耦,并为数据存储创建单个入口点。 You'll probably solve a whole lot more problems other than concurrency with this approach. 除了使用这种方法的并发性,您可能还会解决更多的问题。

not knowing the business rules regarding how an item can be reserved in a basket (such as basket expiry) can you not maintain 'reserved' and 'sold' counts? 不知道有关如何在购物篮中保留商品的业务规则(例如购物篮到期),您是否不能保持“保留”和“已售”计数?

Ok so based on what you say. 好吧,根据您的发言。 I'd think perhaps a compensation based system rather than a transaction based system for handling this. 我认为也许是基于补偿的系统而不是基于交易的系统来处理此问题。 Yes you have transactions on sale but thw reserve you don't 是的,您有交易出售,但没有储备

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

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