[ Transaction(TransactionOption.Required) ]
public class MyTxCfgClass : ServicedComponent
{
public MyTxCfgClass() {}
public void DoTxWork()
{
// set done bit so transaction ends at
// end of method
ContextUtil.DeactivateOnReturn = true;
// clear happy bit so transaction aborts
// if exception is thrown
ContextUtil.MyTransactionVote = TransactionVote.Abort;
... // use ADO.NET to work with databases
// set happy bit so transaction can commit
ContextUtil.MyTransactionVote = TransactionVote.Commit;
}
}
Figure 7SecurityCallContext Methods and Properties
[ Synchronization(SynchronizationOption.Required) ]
public class MyCfgClass : ServicedComponent
{
public MyCfgClass() {}
// executes in object's context
public void One() { ... }
// executes in caller's context
public static void Two() { ... }
// executes in object's context
public string Three { ... }
// executes in caller's context
public static string Four { ... }
}
public class Client
{
public static void Main(string[] args)
{
MyCfgClass cc = new MyCfgClass();
// executes in object's context
cc.One();
// executes in caller's context
MyCfgClass.Two();
// executes in object's context
cc.Three = "red pill";
// executes in caller's context
MyCfgClass.Four = "blue pill";
}
}