Instances of a NGWS class can participate in an automatic transaction, as long as you prepare the class to do so. Each resource accessed by a class instance, or object, enlists in the transaction. For example, if an object uses ADO+ to post money on an account in a database, the resource manager for the database determines if it should execute in a transaction and, if so, it enlists the database in the transaction automatically.
See COM+ 1.0 Interop for instructions on preparing your class to access Windows 2000 services.
[Transaction(TransactionOption.Required)] [ComEmulate()] public class Bar() { //. . . }
[TransactionAttribute(TransactionOption.NotSupported)] [TransactionAttribute(TransactionOption.Support)] [TransactionAttribute(TransactionOption.Required)] [TransactionAttribute(TransactionOption.RequiresNew)]
You can use Transaction, transaction, TransactionAttribute, and transactionattribute interchangeably.
The following table lists and describes each constructor variation.
Attribute Value | Description |
---|---|
NotSupported | This value indicates that the object does not run within the scope of transactions. When a request is processed, its object context is created without a transaction, regardless of whether there is a transaction active.
[Transaction(TransactionOption.NotSupported)] |
Supported | The object will run in the context of an existing transaction, if one exists. If not, it will run without a transaction.
[Transaction(TransactionOption.Supported)] |
Required | The object requires a transaction. It will run in the scope of an existing transaction, if one exists. If not, it will start one.
[Transaction(TransactionOption.Required)] |
RequiresNew | The object requires a transaction and a new transaction will be started for each request.
[Transaction(TransactionOption.RequiresNew)] |
namespace BankClassLibrary { [Guid(“1237e50f-6085-49f7-8293-3febb8580e78”)] public interface IMoveMoney { /* lngPrimeAccount - "From" Account lngSecondAccount - "To" Account lngAmount - Amount of transaction lngTranType - Transaction Type 1 = Withdrawal, 2 = Deposit, 3 = Transfer) Returns: String - Account Balance */ public String Perform ( int lngPrimeAccount, int lngSecondAccount, int lngAmount, int tranType); } [Transaction(TransactionOption.Required)] [Guid(“b963fbbd-d1b1-4a2f-8501-89252dcb116f”)] [ComEmulate(“BankClassLibrary.MoveMoneyInternal\0”)] public class MoveMoney { } internal class MoveMoneyInternal : IMoveMoney { public String Perform ( int lngPrimeAccount, int lngSecondAccount, int lngAmount, int tranType) { // Use IAccount to move money // between two accounts } } [Guid(“41ee971a-93f9-4111-89ee-4e0f4e0fca0a”)] public interface IAccount { public String Post ( int lngAccountNo, int lngAmount); } [Transaction(TransactionOption.Required)] [Guid(“41ee971a-93f9-4111-89ee-4e0f4e0fca0a”)] [ComEmulate(“BankClassLibrary.AccountInternal\0”)] public class Account { } internal class AccountInternal : IObjectControl { public String Post( int lngAccountNo, int lngAmount) { // Use ADO+ to post money into // the account in the database. } void Activate() { //. . . } void Deactivate() { //. . . } bool CanBePooled() { //. . . } }