Class ReflectionDIHelper
Reflection helper class with Dependency Injection support.
public static class ReflectionDIHelper
- Inheritance
-
ReflectionDIHelper
- Inherited Members
Methods
BuildDIParams(IServiceProvider?, IEnumerable<object?>?, ParameterInfo[])
Convenience method to build DI parameters for a contructor or method.
public static object?[] BuildDIParams(IServiceProvider? serviceProvider, IEnumerable<object?>? services, ParameterInfo[] parameters)
Parameters
serviceProvider
IServiceProviderthe service provider to look up for services
services
IEnumerable<object>additional services to look up
parameters
ParameterInfo[]
Returns
- object[]
Remarks
services takes precedence over serviceProvider if both are provided.
BuildDIParams(IServiceProvider?, IEnumerable<object?>?, Type[])
Convenience method to build DI parameters for a contructor or method.
public static object?[] BuildDIParams(IServiceProvider? serviceProvider, IEnumerable<object?>? services, Type[] parameters)
Parameters
serviceProvider
IServiceProviderthe service provider to look up for services
services
IEnumerable<object>additional services to look up
parameters
Type[]
Returns
- object[]
Remarks
services takes precedence over serviceProvider if both are provided.
BuildDIParams(IServiceProvider, ParameterInfo[])
Convenience method to build DI parameters for a contructor or method.
public static object?[] BuildDIParams(IServiceProvider serviceProvider, ParameterInfo[] parameters)
Parameters
serviceProvider
IServiceProviderthe service provider to look up for services
parameters
ParameterInfo[]
Returns
- object[]
BuildDIParams(IServiceProvider, Type[])
Convenience method to build DI parameters for a contructor or method.
public static object?[] BuildDIParams(IServiceProvider serviceProvider, Type[] parameters)
Parameters
serviceProvider
IServiceProviderthe service provider to look up for services
parameters
Type[]
Returns
- object[]
CreateInstance<T>(IServiceProvider?, IEnumerable<object?>?, Type)
Convenience method to create an instance of a class with constructor-based DI.
public static T? CreateInstance<T>(IServiceProvider? serviceProvider, IEnumerable<object?>? services, Type objType)
Parameters
serviceProvider
IServiceProviderthe service provider to look up for services
services
IEnumerable<object>additional services to look up
objType
Type
Returns
- T
Type Parameters
T
Remarks
null is returned if objType is not assignable to T.
services takes precedence over serviceProvider if both are provided.
The first available constructor is used to create the instance. If the class has multiple constructors, which one is chosen is not guaranteed.
CreateInstance<T>(IServiceProvider?, IEnumerable<object?>?, Type, ParameterInfo[])
Convenience method to create an instance of a class with constructor-based DI.
public static T? CreateInstance<T>(IServiceProvider? serviceProvider, IEnumerable<object?>? services, Type objType, ParameterInfo[] constructorParams)
Parameters
serviceProvider
IServiceProviderthe service provider to look up for services
services
IEnumerable<object>additional services to look up
objType
TypeconstructorParams
ParameterInfo[]
Returns
- T
Type Parameters
T
Remarks
null is returned if objType is not assignable to T.
services takes precedence over serviceProvider if both are provided.
The first constructor whose parameters match the constructorParams is used to create the instance.
CreateInstance<T>(IServiceProvider?, IEnumerable<object?>?, Type, Type[])
Convenience method to create an instance of a class with constructor-based DI.
public static T? CreateInstance<T>(IServiceProvider? serviceProvider, IEnumerable<object?>? services, Type objType, Type[] constructorParams)
Parameters
serviceProvider
IServiceProviderthe service provider to look up for services
services
IEnumerable<object>additional services to look up
objType
TypeconstructorParams
Type[]
Returns
- T
Type Parameters
T
Remarks
null is returned if objType is not assignable to T.
services takes precedence over serviceProvider if both are provided.
The first constructor whose parameters match the constructorParams is used to create the instance.
CreateInstance<T>(IServiceProvider, Type)
Convenience method to create an instance of a class with constructor-based DI.
public static T? CreateInstance<T>(IServiceProvider serviceProvider, Type objType)
Parameters
serviceProvider
IServiceProviderthe service provider to look up for services
objType
Type
Returns
- T
Type Parameters
T
Remarks
null is returned if objType is not assignable to T.
The first available constructor is used to create the instance. If the class has multiple constructors, which one is chosen is not guaranteed.
CreateInstance<T>(IServiceProvider, Type, ParameterInfo[])
Convenience method to create an instance of a class with constructor-based DI.
public static T? CreateInstance<T>(IServiceProvider serviceProvider, Type objType, ParameterInfo[] constructorParams)
Parameters
serviceProvider
IServiceProviderthe service provider to look up for services
objType
TypeconstructorParams
ParameterInfo[]
Returns
- T
Type Parameters
T
Remarks
null is returned if objType is not assignable to T.
The first constructor whose parameters match the constructorParams is used to create the instance.
CreateInstance<T>(IServiceProvider, Type, Type[])
Convenience method to create an instance of a class with constructor-based DI.
public static T? CreateInstance<T>(IServiceProvider serviceProvider, Type objType, Type[] constructorParams)
Parameters
serviceProvider
IServiceProviderthe service provider to look up for services
objType
TypeconstructorParams
Type[]
Returns
- T
Type Parameters
T
Remarks
null is returned if objType is not assignable to T.
The first constructor whose parameters match the constructorParams is used to create the instance.