ActivatorUtilities.GetServiceOrCreateInstance 方法

定义

重载

GetServiceOrCreateInstance(IServiceProvider, Type)

从服务提供程序中检索给定类型的实例。 如果找不到该实例,则直接实例化。

GetServiceOrCreateInstance<T>(IServiceProvider)

从服务提供程序中检索给定类型的实例。 如果找不到该实例,则直接实例化。

GetServiceOrCreateInstance(IServiceProvider, Type)

Source:
ActivatorUtilities.cs
Source:
ActivatorUtilities.cs
Source:
ActivatorUtilities.cs

从服务提供程序中检索给定类型的实例。 如果找不到该实例,则直接实例化。

public:
 static System::Object ^ GetServiceOrCreateInstance(IServiceProvider ^ provider, Type ^ type);
public static object GetServiceOrCreateInstance (IServiceProvider provider, Type type);
static member GetServiceOrCreateInstance : IServiceProvider * Type -> obj
Public Shared Function GetServiceOrCreateInstance (provider As IServiceProvider, type As Type) As Object

参数

provider
IServiceProvider

服务提供程序。

type
Type

服务的类型。

返回

已解析的服务或创建的实例。

适用于

GetServiceOrCreateInstance<T>(IServiceProvider)

Source:
ActivatorUtilities.cs
Source:
ActivatorUtilities.cs
Source:
ActivatorUtilities.cs

从服务提供程序中检索给定类型的实例。 如果找不到该实例,则直接实例化。

public:
generic <typename T>
 static T GetServiceOrCreateInstance(IServiceProvider ^ provider);
public static T GetServiceOrCreateInstance<T> (IServiceProvider provider);
static member GetServiceOrCreateInstance : IServiceProvider -> 'T
Public Shared Function GetServiceOrCreateInstance(Of T) (provider As IServiceProvider) As T

类型参数

T

服务的类型。

参数

provider
IServiceProvider

用于解析依赖项的服务提供程序。

返回

T

已解析的服务或创建的实例。

适用于