/// <summary>
        /// Returns the dependencies for the given type. For 
        /// ConstructorExpressionGenerator, dependencies are 
        /// the constructor parameters
        /// </summary>
        /// <param name="type">
        /// The type.
        /// </param>
        /// <returns>
        /// An <see cref="IEnumerable{Expression}"/> representing the type's dependencies
        /// </returns>
        protected override IEnumerable<Expression> CreateDependencyExpressions(Type type)
        {
            return this.GetParametersForConstructor(type).Select(parameter =>
            {
                var eventArgs = new ExpressionGeneratingEventArgs(parameter.ParameterType);
                this.OnExpressionGenerating(eventArgs);
                if (eventArgs.Expression == null)
                {
                    throw new DependencyResolutionException(eventArgs.DependencyType);
                }

                return eventArgs.Expression;
            });
        }
 /// <summary>
 /// Raises the <see cref="DependencyExpressionGenerating"/> event.
 /// </summary>
 /// <param name="args">
 /// The event args for this event. 
 /// </param>
 protected virtual void OnExpressionGenerating(ExpressionGeneratingEventArgs args)
 {
     var handler = this.DependencyExpressionGenerating;
     handler(this, args);
 }
Exemple #3
0
        /// <summary>
        /// The default type resolution handler.
        /// </summary>
        /// <param name="sender">
        /// The sender. This is the <see cref="ExpressionGenerator"/> that is currently building
        /// an expression for a requested type. 
        /// </param>
        /// <param name="args">
        /// The args. The <see cref="ExpressionGeneratingEventArgs.DependencyType"/> property contains the type that 
        /// needs to be resolved.
        /// </param>
        public void ResolveDependencyExpression(object sender, ExpressionGeneratingEventArgs args)
        {
            if (this.IsRegistered(args.DependencyType))
            {
                args.Expression = this.GetRegistration(args.DependencyType).Expression;
            }

            // Not setting args.Expression will cause a DependencyResolution error
        }