示例#1
0
            public InstanceProducer GetInstanceProducer(InjectionConsumerInfo consumer, bool throwOnFailure)
            {
                if (!_convention.CanResolve(consumer.Target) || !_convention.Handles(consumer))
                {
                    return(_decoratee.GetInstanceProducer(consumer, throwOnFailure));
                }

                return(InstanceProducer.FromExpression(
                           consumer.Target.TargetType,
                           _convention.BuildExpression(consumer),
                           _container));
            }
            public InstanceProducer GetInstanceProducer(InjectionConsumerInfo consumer, bool throwOnFailure)
            {
                if (!this.convention.CanResolve(consumer.Target))
                {
                    return(this.decorated.GetInstanceProducer(consumer, throwOnFailure));
                }

                return(InstanceProducer.FromExpression(
                           serviceType: consumer.Target.TargetType,
                           expression: this.convention.BuildExpression(consumer),
                           container: this.container));
            }
 public InstanceProducer GetInstanceProducer(InjectionConsumerInfo consumer, bool throwOnFailure)
 {
     if (this.canResolve(consumer))
     {
         var key = keyFunc(consumer);
         if (!registrations.ContainsKey(key))
         {
             registrations[key] = lifestyle.CreateRegistration <T>(() => resolve(consumer), container);
         }
         var registration = registrations[key];
         return(InstanceProducer.FromExpression(
                    typeof(T),
                    registration.BuildExpression(),
                    container));
     }
     return(innerBehavior.GetInstanceProducer(consumer, throwOnFailure));
 }
            private InstanceProducer ApplyDecorator(InjectionTargetInfo target, Expression expression,
                                                    List <PredicatePair> predicatePairs)
            {
                var visitor = new ContextualDecoratorExpressionVisitor(target, predicatePairs);

                expression = visitor.Visit(expression);

                if (!visitor.AllContextualDecoratorsApplied)
                {
                    throw new InvalidOperationException("Couldn't apply the contextual decorator " +
                                                        visitor.UnappliedDecorators.Last().ToFriendlyName() + ". Make sure that all " +
                                                        "registered decorators that wrap this decorator are transient and don't depend on " +
                                                        "Func<" + target.TargetType.ToFriendlyName() + ">.");
                }

                return(InstanceProducer.FromExpression(target.TargetType, expression, this.container));
            }
示例#5
0
            InstanceProducer IDependencyInjectionBehavior.GetInstanceProducer(
                InjectionConsumerInfo dependency, bool throwOnFailure)
            {
                ThreadLocal <object> local = this.FindThreadLocal(dependency.Target);

                if (local != null)
                {
                    if (dependency.Target.TargetType.IsValueType && this.container.IsVerifying)
                    {
                        throw new InvalidOperationException(
                                  "You can't use Verify() if the factory product contains value types.");
                    }

                    return(InstanceProducer.FromExpression(
                               dependency.Target.TargetType,
                               Expression.Convert(
                                   Expression.Property(Expression.Constant(local), "Value"),
                                   dependency.Target.TargetType),
                               this.container));
                }

                return(this.originalBehavior.GetInstanceProducer(dependency, throwOnFailure));
            }
示例#6
0
 private InstanceProducer CreateConstantValueProducer(ParameterInfo parameter) =>
 InstanceProducer.FromExpression(
     parameter.ParameterType,
     Expression.Constant(parameter.DefaultValue, parameter.ParameterType),
     this.container);