2009 Advent Calendar December 15th


So instead of the generic for the lock we had yesterday we can add a default constructor for convenience in the code and keep the constructor injection for the test code:

1: public class ImportantProvider<T> where T : ImportantInterface, new()
2: {
3: private T _importantObject = new T();
4: private Lock _lock;
5:  
6: public ImportantProvider() : this(new MutexLock())
7: {
8:
9: }
10:  
11: public ImportantProvider(Lock aLock)
12: {
13: _lock = aLock;
14: }
15:  
16: public Transaction Transaction
17: {
18: get
19: {
20: return new Transaction(_importantObject, _lock);
21: }
22: }
23: }

Comments (0)