Class ActivatorUtilities
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- nanoFramework.DependencyInjection.dll
Helper code for the various activator services.
public static class ActivatorUtilities
- Inheritance
-
ActivatorUtilities
- Inherited Members
Methods
CreateInstance(IServiceProvider, Type, params object[])
Instantiate a type with constructor arguments provided directly and/or from an IServiceProvider.
public static object CreateInstance(IServiceProvider provider, Type instanceType, params object[] parameters)
Parameters
provider
IServiceProviderThe service provider used to resolve dependencies.
instanceType
TypeThe type to activate.
parameters
object[]Constructor arguments not provided by the
provider
.
Returns
- object
An activated object of type
instanceType
.
Exceptions
- InvalidOperationException
A suitable constructor for type
instanceType
could not be located. Ensure the type is concrete and all parameters of a public constructor are either registered as services or passed as arguments. Also ensure no extraneous arguments are provided.
GetServiceOrCreateInstance(IServiceProvider, Type, params object[])
Retrieve an instance of the given type from the service provider. If one is not found then instantiate it directly.
public static object GetServiceOrCreateInstance(IServiceProvider provider, Type type, params object[] parameters)
Parameters
provider
IServiceProviderThe service provider.
type
TypeThe type of the service.
parameters
object[]Constructor arguments not provided by the
provider
.
Returns
- object
The resolved service or created instance.
Exceptions
- InvalidOperationException
Unable to resolve a service while attempting to activate a constructor.