简体   繁体   English

Web API /业务逻辑层体系结构

[英]Web API / Business Logic Layer Architecture

I wanted to get some feedback on the structure of an application I inherited last week, and a recommendation for how to best restructure it going forward. 我想获得有关上周继承的应用程序结构的一些反馈,以及有关如何最佳地重组应用程序的建议。 I did not name anything although i'm not saying I'd be better at it :) 我什么也没说,虽然我不是说我会做得更好:)

Here is the nature of it: 这是它的本质:

The Red project has 4 class libraries: Red项目有4个类库:

  1. UI - .NET Web Forms. UI-.NET Web窗体。 This is a portal of sorts that displays information about your sales and work schedule, as well as information on products that come from an API that sits elsewhere. 这是一个门户网站,可显示有关您的销售和工作计划的信息,以及来自其他地方的API的产品信息。
  2. WebApiControllers - a list of WebAPI controllers. WebApiControllers -WebAPI控制器的列表。 They return things like List < Product > (that end up getting serialized). 它们返回诸如List <Product>之类的东西(最终被序列化)。 They are primarily used by another project below called Blue. 它们主要由另一个名为Blue的项目使用。
  3. WebService - a layer whose sole job is to query a private API that sits elsewhere in another part of the US and returns a JSON representation of things like product information. WebService-一层,其唯一工作就是查询位于美国另一部分其他地方的私有API,并返回诸如产品信息之类的JSON表示形式。
  4. Domain - From what I can tell, this seems to have two things going on. -据我所知,这似乎发生了两件事。 The first is it makes calls directly to #3 (webservice) to get data back as json, and then deserializes it to the respective objects. 首先是它直接调用#3(webservice)以将数据作为json返回,然后将其反序列化为相应的对象。 The second is it contains the classes themselves that get deserialized, as well as data transfer objects that are used for #2. 第二个是它包含反序列化的类本身,以及用于#2的数据传输对象。

-- -

The Blue project has 1 class library: A list of aspx forms with ajax calls that point to the Red project's WebApiControllers (#2 above above) 蓝色项目有1个类库:带有ajax调用的aspx表单列表,这些调用指向红色项目的WebApiControllers(上面的第2个)

-- -

The question 问题

There seems to have been some confusion historically over how the red project will grow in time and how it was designed. 历史上似乎对红色项目的时间增长方式和设计方式有些困惑。 As Red uses web forms, there are lots of pieces of data that need to come from the private product API mentioned. 由于Red使用Web表单,因此有许多数据需要来自提到的私有产品API。 As a result I'm seeing the following taking places: 结果,我看到了以下情况:

  1. Some people are instantiating controllers from the WebApiControllers layer and then calling their methods directly to get back the objects. 有人从WebApiControllers层实例化控制器,然后直接调用其方法以获取对象。 This is happening right in the web forms code. 这是在Web窗体代码中发生的。

  2. Others were calling the webservice layer directly, however it is not very easy there are things like request headers, language, userid, and other "messy" details that need to be accessed or instantiated each time a request is made. 其他人则是直接调用Web服务层,但是,每当发出请求时,都需要访问或实例化诸如请求标头,语言,用户ID和其他“混乱”详细信息之类的信息,这并不容易。

I was thinking about making a facade to the webservice layer, and then instructing everyone to access the API through the facade. 我当时正在考虑制作Web服务层的外观,然后指示所有人通过外观访问API。 The only problem is I would be repeating everything that is already done in the WebAPIController class library (so since that has 30 methods, I would have to split those 30 methods across a few different facades or services on this new layer). 唯一的问题是,我将重复WebAPIController类库中已经完成的所有操作(因此,由于该类具有30种方法,因此我必须将这30种方法拆分到新层上的几个不同的外观或服务上)。 I don't know if that's really a problem but wanted to throw it out there and see what you all thought. 我不知道这是否真的是一个问题,但想把它扔在那里,看看大家都在想什么。 I would then tell people that they shouldn't be instantiating controllers but rather using the facade or application service layer going forward. 然后,我要告诉人们,他们不应该实例化控制器,而应该使用外观或应用程序服务层。

What do you all think? 你们怎么想

Thanks! 谢谢!

A facade would work, but as you mentioned, building (and maintaining) it could be a major chore. 外墙可以工作,但是正如您提到的那样,建造(和维护)外墙可能是一件大事。 If the issue is with setting up an HTTP request in a standard way, maybe you could just provide a utility method to send HTTP requests? 如果问题在于以标准方式设置HTTP请求,也许您可​​以只提供一种实用方法来发送HTTP请求? Something like: 就像是:

public dynamic SendWebApiRequest(string url, IDictionary<string, string> parameters)

The method would then take care of setting up an HttpClient , executing the request, and returning the result. 然后,该方法将负责设置HttpClient ,执行请求并返回结果。 Just a thought... 只是一个想法...

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

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