After creating my simple class, I needed to set its
transaction behavior. I can do this via an attribute in my code or via
Component Services MMC snap-in.
There are several options for TransactionOption enumerator,
but I chose RequiresNew to create a new transaction with my component. All available
options are:
·
Disabled: This does not use a current transaction, but also will
not create a new one if it is not available.
·
NotSupported: The component will be created without any control
available on it.
·
Required: This uses a current transaction or creates a new one if
it is not available.
·
RequiresNew: This always creates a new transaction even if a
current transaction is available.
·
Supported: This uses a current transaction, but will not create a
new one if it is not available.
I also set my ApplicationAccessControl for assembly attribute
to true.
Listing 5
namespace AtomicTransactions
{
[assembly: ApplicationAccessControl(true)]
[Transaction(TransactionOption.RequiresNew)]
public class MyTransaction : ServicedComponent
{
Next, I built my assembly and made it COM Visible. I also
created a strong name for this assembly. Finally, I compiled my Class Library
and registered it as a Component Service via Visual Studio command prompt:
C:\AtomicTransactions\bin\Debug>regsvcs
AtomicTransactions.dll
Figure 3