不幸的是,还没有找到任何涉及这方面的帖子。
我创建了一个 WebAPI 应用程序 (ASP.NET Core 2.1) 并利用NSwag来自动生成打字稿服务代理。
我看过控制器操作返回JsonResult& 的代码示例ActionResult。
DTO 通常属于Service Layer,所以我想知道是否可以将它们用作控制器操作输出。
我想知道从控制器操作返回 DTO 是否正确。
控制器:
[Route("api/[controller]/[action]")]
[Authorize]
public class EntryController : ControllerBase
{
private readonly IEntryService _entryService;
public EntryController(
IEntryService entryService
)
{
_entryService = entryService;
}
public async Task<List<EntryDto>> GetMany(long id)
{
var result = await _entryService.GetMany(id);
return result;
}
}
服务:
public class EntryService : BaseService, IEntryService
{
private readonly IEntryHighPerformanceService _entryHighPerformanceService;
public EntryService(
AppDbContext context,
IEntryHighPerformanceService entryHighPerformanceService,
SessionProvider sessionProvider
) : base(
context,
sessionProvider
)
{
_entryHighPerformanceService = entryHighPerformanceService;
}
public async Task<List<EntryDto>> GetMany(long id)
{
var dtos = _entryHighPerformanceService.GetByVocabularyId(id);
return await Task.FromResult(dtos);
}
}
一只萌萌小番薯
千万里不及你
随时随地看视频慕课网APP
相关分类