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.
17 namespace Castle
.Services
.Transaction
19 using System
.Transactions
;
21 public class TransactionScopeResourceAdapter
: IResource
23 private readonly TransactionMode mode
;
24 private readonly IsolationMode isolationMode
;
25 private TransactionScope scope
;
28 /// Initializes a new instance of the <see cref="TransactionScopeResourceAdapter"/> class.
30 /// <param name="mode">The mode.</param>
31 /// <param name="isolationMode">The isolation mode.</param>
32 public TransactionScopeResourceAdapter(TransactionMode mode
, IsolationMode isolationMode
)
35 this.isolationMode
= isolationMode
;
39 /// Implementors should start the
40 /// transaction on the underlying resource
44 TransactionScopeOption scopeOption
= mode
== TransactionMode
.Requires
? TransactionScopeOption
.Required
: TransactionScopeOption
.RequiresNew
;
46 TransactionOptions options
= new TransactionOptions();
50 case IsolationMode
.ReadCommitted
:
51 options
.IsolationLevel
= IsolationLevel
.ReadCommitted
;
53 case IsolationMode
.Chaos
:
54 options
.IsolationLevel
= IsolationLevel
.Chaos
;
56 case IsolationMode
.ReadUncommitted
:
57 options
.IsolationLevel
= IsolationLevel
.ReadUncommitted
;
59 case IsolationMode
.Serializable
:
60 options
.IsolationLevel
= IsolationLevel
.Serializable
;
62 case IsolationMode
.Unspecified
:
63 options
.IsolationLevel
= IsolationLevel
.Unspecified
;
67 scope
= new TransactionScope(scopeOption
, options
);
71 /// Implementors should commit the
72 /// transaction on the underlying resource
81 /// Implementors should rollback the
82 /// transaction on the underlying resource
84 public void Rollback()