views:

26

answers:

0

What are the best practices for dealing with binaries in domain model? I frequently must associate images and other files with business objects and the simple byte[] is not adequate even for the simplest of cases.

The files:

  • Does not have a fixed size and can be quite large thus:
    • Have to be streamed or buffered, preferably in asynchronous manner;
    • Must be cached both on server and client to avoid redundant transfer;
    • On unreliable connections the data transfer can be easily interrupted and has to be resumed - therefore the transfer could start not from the beginning of file but from arbitrary position.
  • Are handled differently than the rest of the data:
    • In web applications are not part of the page content but are downloaded by browser separately;
    • Might be a black box that is handled by third-party software;
    • For performance reasons might not even be stored in the database.

How do we go about expressing such files in domain model (or more specifically, in model classes)? If the rest of the model is transferred via DTOs and WCF web services and persisted with NHibernate in the database, but the files not necessarily so, how to make the file handling transparent, part of the overall transaction where applicable yet support all that is necessary for them to be consumed not only in web applications, but also in ordinary desktop applications.

For WPF and ASP.NET the file object must expose some form of Url property that can be data-bound to WPF controls or used in IMG or HTML tags. Uploading a file is a lot more complicated. Preferably, proper presentation and content practices such as MVVM must be maintained there.

I am really lost here as I am not satisfied with any of my previous solutions. What would you advice?