Figures
© 2004 Microsoft Corporation. All rights reserved.
Figure 3 Declarative Attributes for Classes

Attribute Class
Controls
Applies To
AutoCompleteAttribute
Auto-completion of declarative transactions
Method
ComponentAccessControlAttribute
Class-level access control
Class
ConstructionEnabledAttribute
Object construction (construct string)
Class
EventTrackingAttribute
Events and Statistics
Class
JustInTimeActivationAttribute
Just-in-time (JIT) activation
Class
MustRunInClientContextAttribute
Mandatory activation in client's context
Class
ObjectPoolingAttribute
Object pooling
Class
SecurityRoleAttribute
Role memberships and declarative tests
Class
TransactionAttribute
Declarative transactions
Class
Figure 4 Declarative Attributes for Applications

Attribute Class
Controls
ApplicationAccessControlAttribute
Security settings (except identity)
ApplicationActivationAttribute
Activation mode, either library or server
ApplicationIDAttribute
Unique ID
ApplicationNameAttribute
Name
Figure 5 ContextUtil Methods and Properties

Method or Property
Object Context Interface and Method
DisableCommit
IObjectControl::DisableCommit
EnableCommit
IObjectControl::EnableCommit
GetNamedProperty
IGetContextProperties::GetProperty
IsCallerInRole
IObjectContext::IsCallerInRole
SetAbort
IObjectControl::SetAbort
SetComplete
Object context interface and method
ActivityId
IObjectContextInfo::GetActivityId
ContextId
IObjectContextInfo::GetContextId
DeactivateOnReturn
IConextState::Get/StateDeactivateOnReturn
IsInTransaction
IObjectContextInfo::IsInTransaction
IsSecurityEnabled
IObjectContext::IsSecurityEnabled
MyTransactionVote
IContextState::Get/SetMyTransactionVote
Transaction
IObjectContextInfo::GetTransaction
TransactionId
IObjectContextInfo::GetTransactionId
Figure 6 Managing a Declarative Transaction
[ 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 7 SecurityCallContext Methods and Properties

Method or Property
Call Context Interface and Method
IsCallerInRole
ISecurityCallContext::IsCallerInRole
IsUserInRole
ISecurityCallContext::IsUserInRole
Callers
ISecurityCallContext::get_Item("Callers")
CurrentCaller
CoGetCallContext
DirectCaller
ISecurityCallContext::get_Item("DirectCaller")
IsSecurityEnabled
ISecurityCallContext::IsSecurityEnabled
MinAuthenticationLevel
ISecurityCallContext::get_Item("MinAuthenticationLevel")
NumCallers
ISecurityCallContext::get_Item("NumCallers")
Original Caller
ISecurityCallContext::get_Item("OriginalCaller")
Figure 8 Retrieving the Caller's Name
using System.EnterpriseServices;

[assembly: ApplicationName("MyApp")]
[assembly: ApplicationActivation(ActivationOption.Library)]
[assembly: ApplicationAccessControl(false,  
           AccessChecksLevel = 
             AccessChecksLevelOption.ApplicationComponent)]

namespace ESExample
{
  [ Synchronization(SynchronizationOption.Required) ]
  public class MyCfgClass : ServicedComponent
  {
    public MyCfgClass() {}
    public string GetCallerName()
    {
      return SecurityCallContext.CurrentCall.OriginalCaller.AccountName;
    }
  }
}
Figure 10 Static 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";
  }
}
Page view tracker