What are the best practices for working with binaries in a domain model? I often have to associate images and other files with business objects, and a simple byte [] is not suitable even for the simplest case.
Files:
- It does not have a fixed size and can be quite large, thus:
- Have to be streamed or buffered, preferably asynchronously;
- It must be cached both on the server and on the client to avoid excessive transfer;
- In untrusted connections, data transfer can be easily interrupted and must be resumed - therefore, the transfer can begin not from the beginning of the file, but from an arbitrary position.
- Processed differently than the rest of the data:
- In web applications, part of the page content is not included, but downloaded separately by the browser;
- There may be a black box that is processed by third-party software;
- For performance reasons, they may not even be stored in the database.
How are we going to express such files in a domain model (or, more specifically, in model classes)? If the rest of the model is transmitted through the DTO and WCF web services and stored in NHibernate in the database, but the files are not necessarily how to make the file processing transparent, part of the overall transaction, where applicable, but does not support everything that is necessary for their consumption only in web applications, but also in regular desktop applications.
For WPF and ASP.NET, the file object must expose some form of the Url property, which can be attached to data in WPF elements or used in IMG or HTML tags. Downloading a file is much more complicated. Preferably, appropriate presentation and content methods such as MVVM should be supported there.
I am really lost here, as none of my previous decisions satisfy me. What would you suggest?
source share