COM+ Constructor String

Any COM+ configured component that implements the IObjectConstruct interface has access during construction to a construction string (discussed in Chapter 3), configured in the Component Services Explorer. Serviced components are no different. The base class, ServicedComponent , already implements the IObjectConstruct interface as a virtual method (it has only one method). Your derived serviced component can override the Construct( ) method, as shown in this code sample:

public class MyComponent :ServicedComponent
{ 
   public override void Construct(string constructString) 
   {     
      //use the string. For example:
      MessageBox.Show(constructString);      
   }
}

If the checkbox “Enable object construction” on the component Activation tab is selected, then the Construct( ) method is called after the component’s constructor, providing it with the configured construction string.

You can also enable construction string support and provide a default construction string using the ConstructionEnabled attribute:

[ConstructionEnabled(Enabled = true,Default = "My String")]
public class MyComponent :ServicedComponent
{ 
   public override void Construct(string constructString) 
   {...}
}

The ConstructionEnabled attribute has two public properties. Enabled enables construction string support for your serviced component in the Component Services Explorer (once the component is registered) and Default provides an initial string value. When your component is registered with COM+, the registration process assigns the default string to the constructor string field on the component Activation tab. The default string has no further use after registration. New instances of your component receive as a constructor string the current value of the constructor string field. For example, if the default string is String A, when the serviced component is registered, the value of the constructor string field is set to String A. If you set it to a different value, such as String B, new instances of the component get String B as their construction string. They receive the current value, not the default value.

The ConstructionEnabled attribute has two overloaded constructors. One constructor accepts a Boolean value for the Enabled property; the default constructor sets the value of the Enabled property to true. You can also set the value of the Enabled property explicitly. As a result, the following three statements are equivalent:

[ConstructionEnabled] 
[ConstructionEnabled(true)]
[ConstructionEnabled(Enabled = true)]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset