node.js - 尝试编写一个 Node.js 多层应用程序,就像我在 c# 中使用的那样
问题描述
我已经用 C# 编写了多层应用程序,如下所示。
它使进行全栈测试变得容易。
我已经研究 Node.js 几个星期了,似乎找不到这种分离,尤其是业务逻辑层。
我错过了一些明显的东西吗?
TypeScript 会是更好的选择吗?
层:
DTO - 数据传输对象
DAL - 数据访问层
BUS - 业务逻辑层
UI - 用户界面
这是所有层的部分任务应用程序:
using App.BusinessLogicLayer;
using App.DataAccessLayer;
using App.DataTransferObjects;
using System;
namespace App.DataTransferObjects
{
public class Task
{
public int Id { get; set; }
public string Name { get; set; }
}
}
namespace App.DataAccessLayer
{
public class Tasks
{
public static Task Get()
{
return new Task() { Id = 1, Name = "Task 1" };
}
}
}
namespace App.BusinessLogicLayer
{
public interface ITaskContext
{
Task Get();
}
public class TaskContext : ITaskContext
{
public Task Get()
{
return Tasks.Get();
}
}
public class TaskManager
{
ITaskContext _taskContext;
public TaskManager() : this (new TaskContext())
{
}
public TaskManager(ITaskContext taskContext)
{
_taskContext = taskContext;
}
public Task Get()
{
return _taskContext.Get();
}
}
}
namespace App.UserInterface
{
class Program
{
static void Main(string[] args)
{
TaskManager tm = new TaskManager();
Console.WriteLine(tm.Get().Name);
}
}
}
解决方案
推荐阅读
- javascript - 从递归 indexOf 返回正确的值
- node.js - 如何使用 hapi 测试文件上传?
- reactjs - 向中心前进
- mysql - How to use mysql dump with django?
- elixir - 凤凰丹药中如何显示参考文献二
- f# - F# 模式匹配 JSON 类型提供程序或类类型
- django - 如何使用带有 django-two-factor-auth 的 Twilio 以短信形式发送自定义消息
- typescript - 酶 find() 和 findWhere() 有什么区别?
- python-3.x - 如果另一列中的值相同,则填写 NaN
- python - 如何在 macOS 上使用所有已安装的 pip 包和 pip 擦除整个 python3.x