我应该从另一个 AppService 调用 AppService 吗? [英] Should I be calling an AppService from another AppService?

查看:21
本文介绍了我应该从另一个 AppService 调用 AppService 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

目前我在文件和记录管理系统 (DRMS?) 中工作.由于一些技术限制,我需要存储一个视图"文件和一个源"文件(DOCX 或 XLSX).视图文件是供用户打印、下载和查看日常使用的 PDF 文件,而源文件是可编辑的文件.当用户需要更新一个文件时,他们会下载源,更新它,并上传一个新的视图文件和相应的源文件.

Currently I'm working in a Documents and Records Management System (DRMS?). Because of some technical limitations I need to store a "view" file and a "source" file (DOCX or XLSX). A view file is a PDF file for users to print, download and view for every day usage while a source file is the editable file. When users require to update a file, they will download the source, update it, and upload a new view file and the corresponding source file.

我目前无法实现 XLSX 查看器/编辑器,并且由于文件数量的原因,我无法迁移到 ODF 以使用可用的开源查看器.

I'm not able, at this time, to implement XLSX viewers/editors and, due to the quantity of files, I cannot migrate to ODFs in order to use open source viewers available.

现在我有两个这样的模型:

Right now I have two models like this:

public class Document {
    //Other fields
    public virtual List<DigitalFile> Files { get; set; }
}

public class DigitalFile {
    //Other fields
    public virtual Document FileOf { get; set; }
}

Document 模型包含所有业务"数据,而 DigitalFile 模型包含有关文件本身的数据(路径、url、类型等)

The Document model has all the "business" data while the DigitalFile model has data about the files themselves (path, url, type, etc.)

每次创建文档时,它都会有 1 个视图文件(必需),并且可能有 1 个源文件(某些文档可能无法编辑).由此您可以知道,当创建/更新文档时,至少也会创建/更新 1 个数字文件.

Each time a document is created it will have 1 view file (required) and it may have 1 source file (some documents may not be editable). From this you can know that when a document is created/updated at least 1 digital file will be created/updated as well.

问题/疑问

我将有一个 DocumentAppService 来处理所有 CRUD 操作,但我的疑问就在这里,我应该从另一个 AppService 调用 AppService 吗?我的意思是,当创建一个 Document 时,Create 方法是否应该调用 DigitalFileAppService 中的另一个 Create 方法?还是 DocumentAppService 自己处理所有事情会更好?

I will have a DocumentAppService to handle all the CRUD operations but here's where my doubt comes, should I be calling an AppService from another AppService? I mean, when a Document is created, should the Create method call another Create method in DigitalFileAppService? Or should it be better if DocumentAppService handled everything on its own?

现在,DigitalFile 上的所有 CRUD 操作都与 Document 上的操作相关联,这就是为什么我怀疑为文件实现 AppService 的原因.

Right now all the CRUD operation on DigitalFile are tied to the operations on Document, which is why I'm in doubt of implementing an AppService for the files.

推荐答案

我不建议从同一域中的另一个服务调用应用程序服务.应用服务被设计为从 UI 层调用.它实现了审计日志记录、授权、验证……如果您在同一应用程序层中使用代码,则可能不需要它们.

I don't suggest to call an application service from another service in the same domain. Application services are designed to be called from UI layer. It implements audit logging, authorization, validation... and they will not probably needed if you use a code in the same application layer.

应用程序服务方法是应用程序的公共端点.从另一个调用应用程序服务就像离开您的应用程序并从不同的点进入.如果另一个应用程序服务方法的签名发生变化(因为 UI 中的需求发生变化),您也可能不希望更改应用程序服务方法.

An application service method is a public endpoint of your application. Calling an application service from another is like going out of your application and entering from a different point. You also probably don't want to change an application service method if another application service method's signature changes (because of a requirement change in UI).

我的建议是将共享代码分离到另一个类(可能是域服务)并从两个应用程序服务中使用.

My suggestion is to seperate the shared code into another class (probably a domain service) and use from both application services.

这篇关于我应该从另一个 AppService 调用 AppService 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆