title: Blendability / MVVM for NHibernate
body: <p>I am currently working on a WPF application using NHibernate as my persistence layer. I am trying to use MVVM, partially so that I can use Blend to help design my controls.</p>
  
  <p>I am trying to follow Ayende Rahien's example in <a href="https://github.com/ayende/Effectus" rel="nofollow">Effectus</a> of having one ISession per presenter (except in my case it's a view model instead of a presenter). My view model looks something like this:</p>
  
  <pre><code>public abstract ViewModelBase : INotifyPropertyChanged
  {
      private readonly ISessionFactory _sessionFactory;
  
      protected ViewModelBase(ISessionFactory sessionFactory)
      {
          _sessionFactory = sessionFactory;
      }
  
      private ISession Session
      {
          get
          {
              if (_session == null)
              {
                  _session = _sessionFactory.OpenSession();
              }
              return _session;
          }
      }
      private ISession _session;
  
      // INotifyPropertyChanged implementation here...
  }
  
  public class MainWindowViewModel : ViewModelBase
  {
      public MainWindowViewModel(ISessionFactory sessionFactory)
          : base(sessionFactory)
      {
          var rep = new ProductRepository(this.Session);
          this.Products = new ObservableCollection&lt;Product&gt;(rep.GetAll());
      }
  
      public ObservableCollection&lt;Product&gt; Products
      {
          get
          {
              return _products;
          }
          set
          {
              if (_products != value)
              {
                  _products = value;
                  RaisePropertyChanged("Products");
              }
          }
      }
      private ObservableCollection&lt;Product&gt; _products;
  }
  
  public class DesignMainWindowViewModel : MainWindowViewModel
  {
      public DesignMainWindowViewModel(ISessionFactory sessionFactory)
          : base(sessionFactory)
      {
      }
  
      public new ObservableCollection&lt;Product&gt; Products
      {
          get
          {
              List&lt;Product&gt; products = new List&lt;Product&gt;();
              // fill in design-time products...
              return products;
          }
          set
          {
          }
      }
  }
  </code></pre>
  
  <p>What I would like to achieve is to have a ViewModelLocator that works with Unity to instantiate a design-time view model while working in Blend (and the regular view model when running the software normally). However, I need a design-time ISessionFactory in order to instantiate the DesignMainWindowViewModel.</p>
  
  <p>Three questions:</p>
  
  <ol>
  <li>Is there an easy way to implement an in-memory ISessionFactory?</li>
  <li>Should I try to use an in-memory SQLite database?</li>
  <li>Am I taking the wrong approach to the whole thing?</li>
  </ol>