开发者

In DDD where to save generated files by user?

开发者 https://www.devze.com 2023-04-09 13:28 出处:网络
I have the following architecture in my project: UI -> Application -> Domain -> 开发者_运维技巧Infrastructure (4 tier)

I have the following architecture in my project:

UI -> Application -> Domain -> 开发者_运维技巧Infrastructure (4 tier)

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?

Update:

Here's my folder structure:

In DDD where to save generated files by user?

Thanks for answer, but I want to know too where to save the physic file.

Update 2:

My app is a CMS and these images are content generated by user.


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.


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.

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).

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.

DDD is about designing a solution that models the problem domain as closely as possible; 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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号