ServiceCreatorCallback 委托
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供一种回调机制,它可以即需创建服务的实例。
public delegate System::Object ^ ServiceCreatorCallback(IServiceContainer ^ container, Type ^ serviceType);
C#
public delegate object ServiceCreatorCallback(IServiceContainer container, Type serviceType);
C#
public delegate object? ServiceCreatorCallback(IServiceContainer container, Type serviceType);
C#
[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 );
C#
// 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 发布的服务不会使用尽可能多的其他资源。 若要使用回调函数发布服务,请将 传递给 ServiceCreatorCallbackAddService 的 IServiceContainer方法。
Get |
获取指示指定委托表示的方法的对象。 |
产品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |