ServiceCreatorCallback ServiceCreatorCallback ServiceCreatorCallback ServiceCreatorCallback Delegate

Definition

Provides a callback mechanism that can create an instance of a service on demand.

public delegate System::Object ^ ServiceCreatorCallback(IServiceContainer ^ container, Type ^ serviceType);
[System.Runtime.InteropServices.ComVisible(true)]
public delegate object ServiceCreatorCallback(IServiceContainer container, Type serviceType);
type ServiceCreatorCallback = delegate of IServiceContainer * Type -> obj
Public Delegate Function ServiceCreatorCallback(container As IServiceContainer, serviceType As Type) As Object 
Parameters
container

The service container that requested the creation of the service.

serviceType

The type of service to create.

Return Value
System.Object

The service specified by serviceType, or null if the service could not be created.

Inheritance
ServiceCreatorCallbackServiceCreatorCallbackServiceCreatorCallbackServiceCreatorCallback
Attributes

Examples

The following code example shows how to publish a service using a callback function.

// The following code shows how to publish a service using a callback function.
// Creates a service creator callback.
ServiceCreatorCallback^ callback1 =
   gcnew ServiceCreatorCallback( this, &Sample::myCallBackMethod );

// Adds the service using its type and the service creator callback.
serviceContainer->AddService( myService::typeid, callback1 );
// The following code shows how to publish a service using a callback function.

// Creates a service creator callback.
ServiceCreatorCallback callback1 = 
new ServiceCreatorCallback(myCallBackMethod);

// Adds the service using its type and the service creator callback.
serviceContainer.AddService(typeof(myService), callback1);
' The following code shows how to publish a service using a callback function.

' Creates a service creator callback.
Dim callback1 As New ServiceCreatorCallback _
(AddressOf myCallBackMethod)
       
' Adds the service using its type and the service creator.
serviceContainer.AddService(GetType(myService), callback1)

Remarks

ServiceCreatorCallback provides a mechanism to publish services that you can request to have created when needed, rather than the service being created immediately when the designer loads. You can use a callback function if the service is not essential and may not be used. A service published by using a ServiceCreatorCallback does not use as many additional resources if it is not requested and created. To use a callback function to publish your service, pass a ServiceCreatorCallback to the AddService method of an IServiceContainer.

Applies to

See Also