Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

ActivatorUtilities.CreateInstance Method

Definition

Namespace:
Microsoft.Extensions.DependencyInjection
Assembly:
Microsoft.Extensions.DependencyInjection.Abstractions.dll
Package:
Microsoft.Extensions.DependencyInjection.Abstractions v11.0.0-preview.5.26302.115

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Overloads

Name Description
CreateInstance(IServiceProvider, Type, Object[])

Instantiates a type with constructor arguments provided directly and/or from an IServiceProvider.

CreateInstance<T>(IServiceProvider, Object[])

Instantiates a type with constructor arguments provided directly and/or from an IServiceProvider.

CreateInstance(IServiceProvider, Type, Object[])

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

Instantiates a type with constructor arguments provided directly and/or from an IServiceProvider.

public:
 static System::Object ^ CreateInstance(IServiceProvider ^ provider, Type ^ instanceType, ... cli::array <System::Object ^> ^ parameters);
public static object CreateInstance(IServiceProvider provider, Type instanceType, params object[] parameters);
static member CreateInstance : IServiceProvider * Type * obj[] -> obj
Public Shared Function CreateInstance (provider As IServiceProvider, instanceType As Type, ParamArray parameters As Object()) As Object

Parameters

provider
IServiceProvider

The service provider used to resolve dependencies.

instanceType
Type

The type to activate.

parameters
Object[]

Constructor arguments not provided by the provider.

Returns

An activated object of type instanceType.

Exceptions

.NET 8 and later only: provider is null.

Applies to

CreateInstance<T>(IServiceProvider, Object[])

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

Instantiates a type with constructor arguments provided directly and/or from an IServiceProvider.

public:
generic <typename T>
 static T CreateInstance(IServiceProvider ^ provider, ... cli::array <System::Object ^> ^ parameters);
public static T CreateInstance<T>(IServiceProvider provider, params object[] parameters);
static member CreateInstance : IServiceProvider * obj[] -> 'T
Public Shared Function CreateInstance(Of T) (provider As IServiceProvider, ParamArray parameters As Object()) As T

Type Parameters

T

The type to activate.

Parameters

provider
IServiceProvider

The service provider used to resolve dependencies.

parameters
Object[]

Constructor arguments not provided by provider.

Returns

T

An activated object of type T.

Exceptions

.NET 8 and later only: provider is null.

Applies to


Feedback

Was this page helpful?