Object Construction Sample | (Windows Forms Application) |
This document contains the release information for the .NET Framework Object Construction sample. You will find the following sections below:
This sample demonstrates the use of Object contructor strings in a .Net environment. Object Constructor strings are initialization strings that can be specified or edited administratively (through the Component Services administrative tool), eliminating the need to hard-code configuration information within components.
When object construction is enabled for a component, COM+ will call the IObjectContruct::Construct method that it implements immediately after instantiating the object. The object construction string specified in the component's activation properties is passed as an argument to the method. This, in combination with component code that uses the object string in a meaningful way, effectively provides parameterized object construction.
You can specify a default string value for the construction string in the Default property of the ConstructionEnabledAttribute, in the COM+ catalog, or both.
A component developer might use this feature, for example, to write a component that holds a generic ODBC connection. The object construction string would hold an exact DSN that could be changed through the Component Services admin tool.
Object Contruction strings can be useful in combination with COM+ objection pooling services. See the Platform SDK help for more information.
The .NET Object Constructor sample creates a COM+ component with object construction enabled and a default construction string. On creating an object instance, various component methods display message boxes to demonstrate call order. The user can modify the object construction string by means of the Component Services admin tool and re-run the sample to observe that the object construction string passed to the component instance has changed.
The following bullets briefly describe the technologies used by this sample.
This sample is located in the Technologies\ComponentServices\ObjectConstruction subdirectory of the .NET Framework SDK samples directory.
For Example:
C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\ObjectConstruction
In order to properly build and run this sample, the following steps need to be performed.
Type BuildAll.bat from the command line.
For Example:
C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\ObjectConstruction>buildall.bat
If you're building the sample from Visual Studio 7, you will need to install the OCDemoSvr.dll assembly to the Global Assembly Cache before running the sample. Note: The gacutil.exe program is located in the SDK\v1.1\Bin directory.
For Example:
C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\ObjectConstruction\CS>gacutil -i OCDemoSvr.dll
The sample builds a C# and VB version of the client application and COM+ component. Source code for each language is stored in subdirectories named \CS and \VB. The C# component has 'CS' appended to its name as viewed in the Component Services administrative tool, 'OCDemoServerCS.ObjectConstructionTest'. The VB version is named 'OCDemoServerVB.ObjectConstructionTest'. When working with the sample code, be sure to observe and/or modify the version of the COM+ component that corresponds to the client application you launch.
Review comments in the source code and build.bat files for more information on sample binary creation and registration steps.
In order to run this sample, follow the instructions listed below.
For Example:
C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\ComponentServices\ObjectConstruction\CS>ocdemo.exe
In order to uninstall this sample, follow the instructions listed below.
For the .Net Framework samples to function properly, your Path, Include, and Lib environment variables must be set correctly. In many cases, the SDK install program updates these environment variables for you. However, if you installed the .Net Framework SDK using Visual Studio .NET, or unselected "register environment variables" during setup, these environment variables will not be updated. You can set the Path, Include and Lib environment variables by running SDKVars.bat, located in the <SDKRoot>\Bin directory. SDKVars.bat must be executed in every command shell.