private IActivationExpressionResult CallExportFunc(IActivationStrategy strategy, ParameterInfo parameter, ConstructorParameterInfo parameterInfo, IInjectionScope injectionScope, IActivationExpressionRequest request, bool configurationExternallyOwned) { var exportDelegate = parameterInfo.ExportFunc as Delegate; if (exportDelegate == null) { throw new ArgumentException($"Parameter Info {parameterInfo.ParameterName} is not delegate", nameof(parameterInfo)); } var newRequest = request.NewRequest(parameter.ParameterType, strategy, strategy.ActivationType, RequestType.ConstructorParameter, parameter, false, true); return(ExpressionUtilities.CreateExpressionForDelegate(exportDelegate, ShouldTrackDisposable(configurationExternallyOwned, injectionScope, strategy), injectionScope, newRequest)); }
/// <summary> /// Create call expression for delegate /// </summary> /// <param name="scope"></param> /// <param name="request"></param> /// <param name="activationConfiguration"></param> /// <param name="activationDelegate"></param> /// <returns></returns> protected virtual IActivationExpressionResult CreateCallExpression(IInjectionScope scope, IActivationExpressionRequest request, TypeActivationConfiguration activationConfiguration, ActivationStrategyDelegate activationDelegate) { return(ExpressionUtilities.CreateExpressionForDelegate(activationDelegate, activationConfiguration.ExternallyOwned, scope, request)); }
private Expression CreateLocateExpression(ParameterInfo parameter, IInjectionScope scope, IActivationExpressionRequest request, TypeActivationConfiguration activationConfiguration) { var parameterInfo = FindParameterInfoExpression(parameter, activationConfiguration); if (parameterInfo?.ExportFunc is Delegate) { var newRequest = request.NewRequest(parameter.ParameterType, activationConfiguration.ActivationStrategy, activationConfiguration.ActivationType, RequestType.ConstructorParameter, parameter, true); var delegateValue = (Delegate)parameterInfo.ExportFunc; var expressionCall = ExpressionUtilities.CreateExpressionForDelegate(delegateValue, activationConfiguration.ExternallyOwned, scope, newRequest); var standardParameters = delegateValue.GetMethodInfo() .GetParameters() .All(p => { if (p.ParameterType == typeof(IExportLocatorScope)) { return(true); } if (p.ParameterType == typeof(IDisposalScope)) { return(true); } if (p.ParameterType == typeof(IInjectionContext)) { return(true); } return(true); }); if (standardParameters) { return(expressionCall.Expression); } newRequest = request.NewRequest(parameter.ParameterType, activationConfiguration.ActivationStrategy, activationConfiguration.ActivationType, RequestType.ConstructorParameter, parameter, true); var compiledDelegate = request.Services.Compiler.CompileDelegate(scope, expressionCall); expressionCall = ExpressionUtilities.CreateExpressionForDelegate(compiledDelegate, false, scope, newRequest); return(expressionCall.Expression); } var closedMethod = DynamicLocateMethodInfo.MakeGenericMethod(parameter.ParameterType); return(Expression.Call(Expression.Constant(this), closedMethod, request.ScopeParameter, request.Constants.RootDisposalScope, request.InjectionContextParameter, Expression.Constant(parameter.Name.ToLowerInvariant()), Expression.Constant(true), Expression.Constant(false), Expression.Default(parameter.ParameterType))); }