Fixing Windsor's issue of not resolving components by the order they were registered.
[castle.git] / Facilities / ActiveRecordIntegration / Castle.Facilities.ActiveRecordIntegration / TransactionScopeResourceAdapter.cs
blob93bded08474b2952cbced7b6feea2a09496618a6
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Facilities.ActiveRecordIntegration
17 using Castle.ActiveRecord;
18 using Castle.Services.Transaction;
19 using TransactionMode = Castle.Services.Transaction.TransactionMode;
21 public class TransactionScopeResourceAdapter : IResource
23 private readonly TransactionMode transactionMode;
24 private TransactionScope scope;
26 /// <summary>
27 /// Initializes a new instance of the <see cref="TransactionScopeResourceAdapter"/> class.
28 /// </summary>
29 /// <param name="transactionMode">The transaction mode.</param>
30 public TransactionScopeResourceAdapter(TransactionMode transactionMode)
32 this.transactionMode = transactionMode;
35 public void Start()
37 Castle.ActiveRecord.TransactionMode mode = (transactionMode == TransactionMode.Requires)
38 ? Castle.ActiveRecord.TransactionMode.Inherits
39 : Castle.ActiveRecord.TransactionMode.New;
41 scope = new TransactionScope(mode);
44 public void Commit()
46 scope.VoteCommit();
48 Dispose();
51 public void Rollback()
53 scope.VoteRollBack();
55 Dispose();
58 protected void Dispose()
60 scope.Dispose();