你可以建立一个RESTful业务逻辑层? [英] Can you build a RESTful Business Logic Layer?

查看:1299
本文介绍了你可以建立一个RESTful业务逻辑层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了数据访问层(DAL)RESTful服务我的架构:

  POST http://example.com/data/User
GET | PUT | DELETE http://example.com/data/User/{UserId}

然而,业务逻辑层(BLL),第二非RESTful服务使用:

  POST http://example.com/accountapi/register
POST http://example.com/accountapi/login

这BLL服务,而不是打电话给DAL服务,它直接会谈到数据库中。

您会如何改善这种架构?


  1. 如若BLL服务调用DAL服务?

  2. 我应该放弃的DAL服务,仅暴露BLL服务?

  3. 我应该,不知怎的,我的RESTful服务DAL 注入业务逻辑?如果是的话,怎么样?


解决方案

(1)避免让您的(非REST)的Web服务的业务逻辑层做进一步的(REST式)的HTTP请求到数据访问层。这样做当然会比进行直接方法调用效率较低。但很多更重要的是,它会要求你的BLL Web服务和DAL Web服务部署到不同的Web服务器实例(或独立的集群)。否则,你可以有哪里的一个情况下,所有的你的HTTP工作线程正忙着来提供BLL响应,而每个被阻塞徒劳地等待一个免费的HTTP工作线程来服务它DAL响应。这可能导致摊位(如果你超时/重试处理)或直接死锁(如果你不这样做)。

(2和3)如果你的Web服务客户端既需要业务逻辑和数据访问,提供这些作为一套统一的服务。在内部,他们都依赖于相同的数据访问层的方法调用:这只是面向Web服务实现数据做只有一个数据访问层调用,而业务逻辑的面向Web服务实现可能让不少DAL电话。你最肯定要单独构建的BLL和DAL层Web服务层之下,虽然。

我喜欢把Web服务作为实现用户谁恰巧是其他方案面向presentation层的只是一部分。

I've built a RESTful service for the Data Access Layer (DAL) of my architecture:

POST http://example.com/data/User
GET|PUT|DELETE http://example.com/data/User/{UserId}

However, for the Business Logic Layer (BLL), a second non-RESTful service is used:

POST http://example.com/accountapi/register
POST http://example.com/accountapi/login

This BLL service, instead of making calls to the DAL service, it talks directly to the database.

How would you improve this architecture?

  1. Should the BLL service call the DAL service ?
  2. Should I drop the DAL service and only expose the BLL service ?
  3. Should I, somehow, inject business logic on my RESTful DAL service ? If yes, how ?

解决方案

(1) Avoid having your (non-REST) web service business logic layer make further (RESTful) HTTP requests onto the data access layer. Doing so of course would be less efficient than making direct method calls. But much more importantly, it would require you to deploy the BLL web services and the DAL web services onto separate web server instances (or separate clusters). Otherwise you can have a case where all your HTTP worker threads are busy trying to serve up BLL responses, and each is blocked waiting fruitlessly for a free HTTP worker thread to serve it a DAL response. This can lead to stalls (if you do timeout/retry processing) or outright deadlocks (if you don't).

(2 and 3) If your web service clients need both business logic and data access, provide those as a unified set of services. Internally they both depend on the same data access layer method calls: it's just that the data oriented web service implementations make just one data access layer call while the business logic oriented web service implementations may make many DAL calls. You do most definitely want to structure the BLL and DAL layers separately beneath the web service layer though.

I like to think of the web services as just the part of the presentation layer oriented towards "users" who happen to be other programs.

这篇关于你可以建立一个RESTful业务逻辑层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆