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
serviceProviderIServiceProviderthe service provider to look up for services
servicesIEnumerable<object>additional services to look up
parametersParameterInfo[]
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
serviceProviderIServiceProviderthe service provider to look up for services
servicesIEnumerable<object>additional services to look up
parametersType[]
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
serviceProviderIServiceProviderthe service provider to look up for services
parametersParameterInfo[]
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
serviceProviderIServiceProviderthe service provider to look up for services
parametersType[]
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
serviceProviderIServiceProviderthe service provider to look up for services
servicesIEnumerable<object>additional services to look up
objTypeType
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
serviceProviderIServiceProviderthe service provider to look up for services
servicesIEnumerable<object>additional services to look up
objTypeTypeconstructorParamsParameterInfo[]
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
serviceProviderIServiceProviderthe service provider to look up for services
servicesIEnumerable<object>additional services to look up
objTypeTypeconstructorParamsType[]
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
serviceProviderIServiceProviderthe service provider to look up for services
objTypeType
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
serviceProviderIServiceProviderthe service provider to look up for services
objTypeTypeconstructorParamsParameterInfo[]
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
serviceProviderIServiceProviderthe service provider to look up for services
objTypeTypeconstructorParamsType[]
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.