Esempio n. 1
0
        private IEnumerable <ServiceBinding> Resolve <TElement>(IInstanceFactoryResolver resolver, Type type)
        {
            foreach (InstanceFactory instanceFactory in resolver.TryResolveAll(typeof(TElement)))
            {
                var newBinding = new ServiceBinding(type, BindingMetadata.GeneratedInstance, instanceFactory.Context.Expression, instanceFactory.Context.Expression.Type, ConstructorResolvers.Default, Lifetimes.Transient);

                var expression = Expression.Lambda <Func <TElement> >(ExpressionCompiler.OptimizeExpression(instanceFactory.Context));
                Func <Scoped, Expression <Func <TElement> > > del = scoped => expression; // we need to put this in a variable of this type or cast it else the static return type of the delegate will turn into a object..
                var factory = new InstanceFactory(type, new ExpressionContext(expression), del);
                newBinding.Factories.Add(factory);
                yield return(newBinding);
            }
        }
        public static LambdaExpression CreateLambda <T>(ReadOnlyExpressionContext context)
        {
            Expression expression = ExpressionCompiler.OptimizeExpression(context);

            return(Expression.Lambda <Func <T> >(expression));
        }