REST API架构 [英] REST API Architecture

查看:88
本文介绍了REST API架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在设计REST API,但在工作中就对象的构成进行了辩论。我们目前有一个实体框架模型,其中一些控制器包装器用作DAL。我们显然还有REST服务部分,它将基于ASP.NET Web API。这意味着我们有两组对象 - 数据层对象和服务层对象。



争论的焦点是核心业务逻辑是否需要第三组所有实际工作/处理完成的层。我的想法是,所有其他对象应该转换为业务对象,这将是常见的并用于所有核心处理。然后,该对象还将有一些方法将逻辑保存在一个公共位置(而不是简单地将所有内容放在静态帮助器方法中)。然而,其他人觉得它难以管理,并且更喜欢在业务层中以混合匹配的方式处理服务和数据对象。



你能推荐任何好的模式或标准跟着?

解决方案

我有点厌恶回答这个问题,因为我认为没有一个的答案,因此以下是一个意见,希望你会得到多个意见。



鉴于你的描述,我会加强EF模型并使其成为商业模式,否定对第三种模式的需求一组类,这使得架构保持良好和封装。这就是将EF视为数据存储的合理原因。立即浮现在脑海中的两个是:非常异构的存储环境;商业模式与EF模型有很大的不同,如果设计得很好,我认为不应该这样。在这种情况下,第三层有各种意义。



想想我刚才说的话,我会进行以下心理测试:

1.大部分数据是否都存在于数据库中?

2现有的EF是否像任何名义商业模式一样构建(例如,将业务类紧密映射到EF类)。



如果上述答案是肯定的,我''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''')自动的)。

I am currently in the process of designing a REST API but got into a debate at work about the makeup of the objects. We currently have an Entity Framework model with some controller wrappers around them used as the DAL. We also obviously have the REST service part which will be based on ASP.NET Web API. This means we have two sets of objects - the data layer objects and the service layer objects.

The debate was around whether a third set was necessary for the core business logic layer where all the real work/processing gets done. I am of the mind that all other objects should convert into a Business Object which will be common and used in all core processing. This object will also then have methods on it to keep logic in a common place (as opposed to simply putting everything in static helper methods). However others feel its unmanageable and prefer to deal with both service and data objects in a mix-match approach in the business layer.

Can you recommend any good patterns or standards to follow?

解决方案

I''m a bit loathe to answer this as I don''t think there is an answer, as such the following is an opinion and hopefully you''ll get multiple opinions.

Given what you describe, I''d beef up the EF model and make that the business model, negating the need for the third set of classes, this keeps the architecture all nice and encapsulated. That said there are legitimate reasons for just treating the EF as a data store. Two that immediately spring to mind are: a very heterogeneous storage environment; the business model is significantly different to the EF model, which it shouldn''t be if well designed I suppose) in which case the third layer makes all kinds of sense.

Thinking about what I''ve just said I''d run the following mental test:
1. Is most of the data persisted in the database?
2. Is the existing EF structured like any notional Business model (e.g. close mapping of business classes to the EF classes).

If the answer to the above is yes, I''d go for the EF model as business model approach but I''d make sure that persistence stuff doesn''t bleed through, i.e. the EF classes are agnostic of the fact they are stored (other than the cruft the EF puts in automagically).


这篇关于REST API架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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