COM+ Transactions
You
can configure your serviced component to
use the five available COM+ transaction support options by using the
Transaction
attribute. The
Transaction attribute’s
constructor
accepts
an
enum
parameter
of type
TransactionOption
, defined as:
public enum TransactionOption
{
Disabled,
NotSupported,
Supported,
Required,
RequiresNew
}For example, to configure your serviced component to require a
transaction, use the TransactionOption.Required
value:
[Transaction(TransactionOption.Required)]
public class MyComponent :ServicedComponent
{...}The five enum values of TransactionOption map to
the five COM+ transaction support options discussed in Chapter 4.
When you use the Transaction attribute to mark
your serviced component to use transactions, you implicitly set it to
use JITA and require activity-based synchronization as well.
The Transaction attribute has an overloaded
default constructor, which sets the transaction support to
TransactionOption.Required. As a result, the
following two statements are equivalent:
[Transaction] [Transaction(TransactionOption.Required)]
Voting on the Transaction
Not
surprisingly,
you
use the ContextUtil
class to vote on the
transaction’s outcome. ContextUtil has a
static property of the enum type
TransactionVote
called MyTransactionVote.
TransactionVote
is defined
as:
public enum TransactionVote {Abort,Commit}
Example 10-5 shows a transactional serviced component
voting on its transaction outcome using
ContextUtil. Note that the ...