ServiceCreatorCallback 委托

定义

提供一种回调机制,它可以即需创建服务的实例。

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

参数

container
IServiceContainer

请求创建服务的服务容器。

serviceType
Type

要创建的服务的类型。

返回值

serviceType 指定的服务;如果未能创建服务,则为 null

属性

示例

下面的代码示例演示如何使用回调函数发布服务。

// 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)

注解

ServiceCreatorCallback 提供了一种机制来发布可以请求在需要时创建的服务,而不是在设计器加载时立即创建服务。 如果服务不是必需的且不能使用,则可以使用回调函数。 如果未请求和创建服务,则使用 ServiceCreatorCallback 发布的服务不会使用尽可能多的其他资源。 若要使用回调函数发布服务,请将 传递给 ServiceCreatorCallbackAddServiceIServiceContainer方法。

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。

适用于

另请参阅