Share via


Object Construction

COM+ object construction enables you to specify initialization information externally, eliminating the need to hard-code configuration information within a class. Object constructors used in conjunction with object pooling provide the capabilities of a resource dispenser, without the effort of implementing a full resource dispenser.

You can configure object construction by applying the ConstructionEnabledAttribute attribute to a class that derives from the System.EnterpriseServices.ServicedComponent class.

The following example sets the default property value of the TestObjectConstruct class to the string "Hello world".

Server

Imports System.EnterpriseServices
Imports System
<assembly: ApplicationName("OCDemo")>

Namespace OCDemo 
<ConstructionEnabled([Default] := "Hello world")> _
      Public Class TestObjectConstruct 
      Inherits ServicedComponent
            Public Sub New()
                  ' First method to be called.
            End Sub 

            Public Overrides Sub Construct(constructString As String)
                  ' Called after constructor.
            End Sub 

            Public Sub DoWork()
            End Sub 
      End Class 
End Namespace 
[C#]
using System;
using System.EnterpriseServices;
[assembly : ApplicationName("OCDemo")]

namespace OCDemo
{
      [ConstructionEnabled(Default="Hello world")]
      public class TestObjectConstruct : ServicedComponent
      {
            public TestObjectConstruct()
            {
                  // First method to be called.
            }
            public override void Construct(string constructString)
            {
                  // Called after constructor.
            }
            public void DoWork () {}
      }
}

Client

Public Class App
      Overloads Public Shared Sub Main()
            Dim order As New TestObjectConstruct()
            order.DoWork()
      End Sub
End Class
[C#]
public class App
{
      public static int Main()
      {
            TestObjectConstruct order = new TestObjectConstruct();
            order.DoWork();
      }
}

See Also

Summary of Available COM+ Services | ConstructionEnabledAttribute | System.EnterpriseServices Namespace