Using IObjectControl COM Interface of Component Class Factory

Using IObjectControl COM Interface of Component Class Factory

IObjectControl is the second COM interface (besides the COM interface IObjectContext) of the component class factory, as stored in MTS when the component is installed. This interface is useful for carrying out tasks during activation and deactivation of the component. In VB, we can implement this interface within the component using the Implements keyword – Implements ObjectControl.

This interface provides a method to control how an object interacts with MTS. This ObjectControl interface must give three methods: Activate, Deactivate, and CanBePooled. Activate is called when an instance of component is created, either for the first time or from the cached object pool if it has been deactivated after use. Deactivate is called just before it is returned to the cache after use. CanBePooled is used to tell MTS whether the component instance can be pooled or not.

However, whether you implement this interface is entirely optional.If you need to carry out any processing when the component is activated or deactivated, you must implement it so that MTS will provide the Activate and Deactivate events. Any other initialization and clean-up can be done in the Activate and Deactivate methods. These can also be used to create and destroy instances of any other objects, which needs to be used.


Share the Post: