小编Rie*_*edi的帖子

具有干净架构和 AutoMapper 的 asp.net core - 将 DTO 通过服务层传递到控制器

我构建了一个具有干净架构的 asp.net core Web api,我的层是:

  • 网络应用程序接口
  • 服务层
  • 领域层
  • 数据层

在我的 Web API 中,我从外部 Exchange Web 服务加载数据。我想为我的客户提供我自己的 Web API。

为此,我在数据层实现了一个存储库,该存储库从外部 Web 服务获取数据作为 Class 的对象Appointment。

在服务层,我使用 AutoMapper 将对象映射到我自己的类EventDTO。

现在我不知道从 Web API 控制器访问这些数据的最佳实践是什么。

在我看来,当遵循干净的架构原则时,我必须EventDTO将EventEntity. 但是当我这样做时,我有两个 100% 相同的对象,因为没有逻辑,EventEntity并且我做了两次相同的映射。那没有意义?!?

但是当我将直接传递EventDTO给控制器​​时,它会打破干净架构的原则吗?

事件控制器.cs

namespace Example.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class EventController : ControllerBase
    {
        private readonly IEventService eventService;

        public EventController (IEventService eventService)
        {
            this.eventService = eventService ?? throw new ArgumentNullException(nameof(eventService));
        }

        [HttpGet]
        public async Task<IActionResult> …
Run Code Online (Sandbox Code Playgroud)

dto automapper service-layer clean-architecture asp.net-core-webapi

1
推荐指数
1
解决办法
5460
查看次数