private Type GetDecorateeFactoryTypeOrNull() => ( from parameter in this.decoratorConstructor.GetParameters() where DecoratorHelpers.IsScopelessDecorateeFactoryDependencyType( parameter.ParameterType, this.registeredServiceType) || DecoratorHelpers.IsScopeDecorateeFactoryDependencyParameter( parameter.ParameterType, this.registeredServiceType) select parameter.ParameterType) .FirstOrDefault();
// The constructor parameter in which the factory for creating decorated instances should be injected. private Expression BuildExpressionForDecorateeFactoryDependencyParameter( ParameterInfo param, Type serviceType, Expression expr) { if (DecoratorHelpers.IsScopelessDecorateeFactoryDependencyType(param.ParameterType, serviceType)) { // We can't call CompilationHelpers.CompileExpression here, because it has a generic type and // we don't know the type at runtime here. We need to do some refactoring to CompilationHelpers // to get that working. expr = CompilationHelpers.OptimizeScopedRegistrationsInObjectGraph(this.Container, expr); var instanceCreator = Expression.Lambda(Expression.Convert(expr, serviceType)).Compile(); return(Expression.Constant(instanceCreator)); } return(null); }
private IEnumerable <Registration> GetDecorateeFactoryDependencies(KnownRelationship[] relationships) => from relationship in relationships where DecoratorHelpers.IsScopelessDecorateeFactoryDependencyType( relationship.Dependency.ServiceType, this.e.RegisteredServiceType) select relationship.Dependency.Registration;
private bool DecoratorNeedsADecorateeFactory() => ( from parameter in this.decoratorConstructor.GetParameters() where DecoratorHelpers.IsScopelessDecorateeFactoryDependencyType(parameter.ParameterType, this.registeredServiceType) select parameter) .Any();