gpt4 book ai didi

c# - Web Api - 将工作流与 BL 分离

转载 作者:行者123 更新时间:2023-11-30 17:31:35 24 4
gpt4 key购买 nike

<分区>

我和我的队友争论 Web API Controller 应该保存什么代码。我们都同意 Controller 不应包含业务逻辑,但我们不同意放置工作流的位置以及工作流是否应与业务逻辑完全分离。

他们认为端点应该看起来像这样:

Controller 代码:

public Response EndPoint(...)
{
var flow = new SomeFlow();
var response = flow.RunFlow(...);
return response;
}

流程代码:

public class SomeFlow
{
public HttpResponseMessage Activate(....)
{
var service = new Service();
var entities = someService.GetEntities();
if(entities == null) return new HttpResponseMessage(HttpStatusCode.NotFound);

foreach(var entity in entities)
{
BusinessLogicClass/Model.DoSomething(entity)
}

.....
.....
}
}

SomeFlow.cs 类位于解决方案中的业务逻辑项目下。

我已经向他们展示了这个 stackoverflow 答案: https://stackoverflow.com/a/12694104/9062092但他们仍然说这段代码更具可读性。

最让我不安的是流类位于业务逻辑项目下,我认为这鼓励开发人员将业务逻辑放在流类中并将 BL 与工作流耦合。我看不出有什么理由创建这个只有一个公共(public)方法并且只会在项目中使用一次的类。

它在两种方式上都是可测试的,但当它位于流类内部时,测试纯 BL 有点困难。

工作流是否被视为业务逻辑?

感谢您的回复!

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com