예제 #1
0
 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();
예제 #2
0
        // 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);
        }
예제 #3
0
 private IEnumerable <Registration> GetDecorateeFactoryDependencies(KnownRelationship[] relationships) =>
 from relationship in relationships
     where DecoratorHelpers.IsScopelessDecorateeFactoryDependencyType(
     relationship.Dependency.ServiceType, this.e.RegisteredServiceType)
 select relationship.Dependency.Registration;
예제 #4
0
 private bool DecoratorNeedsADecorateeFactory() => (
     from parameter in this.decoratorConstructor.GetParameters()
         where DecoratorHelpers.IsScopelessDecorateeFactoryDependencyType(parameter.ParameterType, this.registeredServiceType)
     select parameter)
 .Any();