1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
;
24 public class TransactionScopeResourceAdapter
: IResource
26 private readonly TransactionMode transactionMode
;
27 private TransactionScope scope
;
30 /// Initializes a new instance of the <see cref="TransactionScopeResourceAdapter"/> class.
32 /// <param name="transactionMode">The transaction mode.</param>
33 public TransactionScopeResourceAdapter(TransactionMode transactionMode
)
35 this.transactionMode
= transactionMode
;
39 /// Implementors should start the
40 /// transaction on the underlying resource
44 Castle
.ActiveRecord
.TransactionMode mode
= (transactionMode
== TransactionMode
.Requires
)
45 ? Castle
.ActiveRecord
.TransactionMode
.Inherits
46 : Castle
.ActiveRecord
.TransactionMode
.New
;
48 scope
= new TransactionScope(mode
);
52 /// Implementors should commit the
53 /// transaction on the underlying resource
63 /// Implementors should rollback the
64 /// transaction on the underlying resource
66 public void Rollback()
74 /// Releases unmanaged and - optionally - managed resources
76 protected void Dispose()