title: Files in domain model
body: <p>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.</p>
  
  <p>The files:</p>
  
  <ul>
  <li>Does not have a fixed size and can be quite large thus:
  
  <ul>
  <li>Have to be streamed or buffered, preferably in asynchronous manner;</li>
  <li>Must be cached both on server and client to avoid redundant transfer;</li>
  <li>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.</li>
  </ul></li>
  <li>Are handled differently than the rest of the data:
  
  <ul>
  <li>In web applications are not part of the page content but are downloaded by browser separately;</li>
  <li>Might be a black box that is handled by third-party software;</li>
  <li>For performance reasons might not even be stored in the database.</li>
  </ul></li>
  </ul>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>I am really lost here as I am not satisfied with any of my previous solutions. What would you advice?</p>