Freigeben über


2009 Advent Calendar December 9th

With the solution we have from yesterday we still have a big problem. Whoever uses ImportantObject must also create the transaction. That is really a bad idea since it is too easy to use the ImportantObject in an unsafe way (i.e. not using transactions at all). To fix this I'm going to introduce an ImportantProvider:

    1:      public class Given_an_ImportantProvider
   2:      {
   3:          private ImportantProvider _importantProvider = new ImportantProvider(new DummyObject());
   4:   
   5:          [Fact]
   6:          void It_should_return_a_transaction()
   7:          {
   8:              Assert.NotNull(_importantProvider.Transaction);            
   9:          }
  10:      }
  11:   
  12:      public class ImportantProvider
  13:      {
  14:          private ImportantInterface _importantObject;
  15:   
  16:          public ImportantProvider(ImportantInterface importantObject)
  17:          {
  18:              _importantObject = importantObject;
  19:          }
  20:   
  21:          public Transaction Transaction
  22:          {
  23:              get
  24:              {
  25:                  return new Transaction(_importantObject, new MutexLock());
  26:              }
  27:          }
  28:      }