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

查看:242
本文介绍了我应该从另一个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个源文件(某些文档可能不可编辑).由此可以知道,在创建/更新文档时,还将至少创建/更新一个数字文件.

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吗?我的意思是,在创建文档时,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天全站免登陆