简体   繁体   English

在DDD中,用户在哪里保存生成的文件?

[英]In DDD where to save generated files by user?

I have the following architecture in my project: 我的项目中具有以下架构:

UI -> Application -> Domain -> Infrastructure (4 tier) UI->应用程序->域->基础结构 (4层)

I need to allow user to upload a image, where the better place to keep the files generated by the user? 我需要允许用户上传图像,在哪里保存用户生成的文件的更好位置? In a folder in UI project? 在UI项目的文件夹中?

Update: 更新:

Here's my folder structure: 这是我的文件夹结构:

在此处输入图片说明

Thanks for answer, but I want to know too where to save the physic file. 感谢您的回答,但我也想知道将物理文件保存在哪里。

Update 2: 更新2:

My app is a CMS and these images are content generated by user. 我的应用是CMS,这些图像是用户生成的内容。

Let the Infrastructure handle those details. 让基础架构处理这些细节。 If there needs to be any sort of validation or business rules, then just deal with it like regular data, because that is all it is. 如果需要任何形式的验证或业务规则,则只需像常规数据一样对其进行处理,因为仅此而已。 The only difference is you are probably saving this data in a different place, but that is an implementation detail. 唯一的区别是您可能会将这些数据保存在其他位置,但这只是实现细节。

Later on, you might want store those files in the database, or in version control... still implementation details that can be abstracted away into the infrastructure layer. 稍后,您可能想要将这些文件存储在数据库中或版本控制中...仍然可以抽象到基础结构层的实现细节。

Update: Ok, where to physically save the file on the drive. 更新:好的,将文件实际保存在驱动器上的位置。 If it were me, would not store them mixed in with my code, because that seems like it could get complicated quickly. 如果是我,则不要将它们与我的代码混合存储,因为这看起来可能会很快变得复杂。 Say you wanted to start storing these files in version control, now you are mixing code in one version control system with data in another all in the same place. 假设您想开始将这些文件存储在版本控制中,现在您将一个版本控制系统中的代码与另一个版本中的数据混合在同一位置。 I would probably pick a place at least a little separated from your code: 我可能会选择一个至少与您的代码分开一点的地方:

Two thoughts: 两个想法:

Venus.Application
Venus.Domain
Venus.Infra
Venus.Tests
Venus.UI.Web
Venus.Files (or Data)

Or 要么

Venus.Application
Venus.Domain
Venus.Infra
    \Files (or Data)
Venus.Tests
Venus.UI.Web

I did do something like for uploading user xml files, and I did save the files in a folder like the second one, and it worked out alright for a while, but then I decided that those files were better off stored in the database as text then written out only when needed to be exported. 我确实做了类似上载用户xml文件的操作,并且确实将文件保存在第二个文件夹中,并且可以正常工作一段时间,但后来我决定最好将这些文件作为文本存储在数据库中。然后仅在需要导出时才写出。

I think it depends on the character of the image files being uploaded. 我认为这取决于要上传的图像文件的特征。 What is their intended use, how long do they need to be stored. 它们的预期用途是什么,需要保存多长时间。 For short-term images that don't need to be around for very long, TEMP is a splendid location for them. 对于不需要长时间存在的短期图像,TEMP是它们的绝佳位置。

If they are meant to be long-term / permanent files, then you need to think about how they fit into your domain model. 如果它们是长期/永久文件,那么您需要考虑一下它们如何适合您的域模型。 If your domain is centered around working with users' images, then perhaps they deserve a place in your Domain folder (bear in mind you can't forget about the security aspects of copying a user-uploaded file to a location not publicly accessible from the webserver, but I'm assuming you're taking care of that). 如果您的域集中在处理用户图像上,那么也许他们应该在您的Domain文件夹中保留一个位置(请记住,您不能忘记将用户上传的文件复制到无法从用户公开访问的位置的安全性方面)网络服务器,但我假设您正在处理)。

However, if these images aren't so critical to the domain, and perhaps they are being used to beautify / customize the user's web experience, then perhaps they belong somewhere in the UI folder. 但是,如果这些图像对域不是很重要,并且可能被用于美化/自定义用户的Web体验,那么它们可能属于UI文件夹中的某个位置。

DDD is about designing a solution that models the problem domain as closely as possible; DDD旨在设计一种解决方案,以尽可能紧密地对问题域进行建模。 you should know your domain best, use your best judgment. 您应该最好地了解自己的领域,并根据自己的最佳判断。

In terms of where to physically store them, I'd personally store them in the database by storing them as binary in one of the binary data types provided by the database. 关于将它们物理存储在何处,我个人将它们作为二进制存储在数据库提供的一种二进制数据类型中,从而将它们存储在数据库中。

You could simply have an Image property on your object/DTO that you convert to bytes when saving. 您可以在对象/ DTO上简单地拥有一个Image属性,在保存时将其转换为字节。

In my experience keeping all user data in the database rather than using physical files is much less hassle because you don't have to worry about unique file names, permissions, and moving servers/ deployment etc is easier because it's all contained in the database which you can backup and move about with ease. 根据我的经验,将所有用户数据保留在数据库中而不是使用物理文件的麻烦要少得多,因为您不必担心唯一的文件名,权限,并且移动服务器/部署等更为容易,因为它们全部包含在数据库中,您可以轻松备份和移动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM