示例#1
0
 private void ApplyMethodInjectors(ExpressionBuildingEventArgs e, MethodInfo[] methods)
 {
     foreach (var method in methods)
     {
         this.ApplyMethodInjector(e, method);
     }
 }
示例#2
0
 void Intercept(object sender, ExpressionBuildingEventArgs e)
 {
     if (AspectUtility.IsDecorated(e.KnownImplementationType, Proxy.Configuration))
     {
         e.Expression = Expression.Convert(
             Expression.Invoke(Expression.Constant(_createProxy), e.Expression),
             e.RegisteredServiceType);
     }
 }
示例#3
0
            private static void AddKnownRelationships(ExpressionBuildingEventArgs e,
                                                      InstanceProducer[] dependencies)
            {
                var relationships =
                    from dependency in dependencies
                    select new KnownRelationship(e.KnownImplementationType, e.Lifestyle, dependency);

                foreach (KnownRelationship relationship in relationships)
                {
                    e.KnownRelationships.Add(relationship);
                }
            }
        public void ExpressionBuildingEventArgsExpressionProperty_SetWithNullReference_ThrowsArgumentNullException()
        {
            // Arrange
            var eventArgs = new ExpressionBuildingEventArgs(
                typeof(IPlugin),
                typeof(PluginImpl),
                Expression.Constant(new PluginImpl()),
                Lifestyle.Transient);

            // Act
            eventArgs.Expression = null;
        }
示例#5
0
            private static void ReplaceExpression(ExpressionBuildingEventArgs e, MethodInfo method,
                                                  InstanceProducer[] dependencies)
            {
                Delegate injectorDelegate = BuildInjectorDelegate(e.KnownImplementationType, method);

                var dependencyExpressions =
                    from dependency in dependencies
                    select dependency.BuildExpression();

                var parameters = (new Expression[] { e.Expression }).Concat(dependencyExpressions);

                e.Expression = Expression.Invoke(Expression.Constant(injectorDelegate), parameters);
            }
示例#6
0
            private void ApplyMethodInjector(ExpressionBuildingEventArgs e, MethodInfo method)
            {
                VerifyMethod(method);

                var dependencies = (
                    from parameter in method.GetParameters()
                    select this.container.GetRegistration(parameter.ParameterType, throwOnFailure: true))
                                   .ToArray();

                ReplaceExpression(e, method, dependencies);

                AddKnownRelationships(e, dependencies);
            }
        public void ExpressionBuildingEventArgsExpressionProperty_SetWithNullReference_ThrowsArgumentNullException()
        {
            // Arrange
            var eventArgs = new ExpressionBuildingEventArgs(
                typeof(PluginImpl),
                Expression.Constant(new PluginImpl()),
                Lifestyle.Transient,
                new Collection <KnownRelationship>());

            // Act
            Action action = () => eventArgs.Expression = null;

            // Assert
            AssertThat.Throws <ArgumentNullException>(action);
        }
示例#8
0
            internal void ExpressionBuilding(object sender, ExpressionBuildingEventArgs e)
            {
                var methods = this.GetMethodsToInject(e.KnownImplementationType);

                this.ApplyMethodInjectors(e, methods);
            }
 public ProfileData(ExpressionBuildingEventArgs info, TimeSpan elapsed)
 {
     this.Info    = info;
     this.Elapsed = elapsed;
 }