コード例 #1
0
        internal void AddAppliedDecorator(Type decoratorType, Container container, Lifestyle lifestyle, 
            Expression decoratedExpression, IEnumerable<KnownRelationship> decoratorRelationships = null)
        {
            var registration = new ExpressionRegistration(decoratedExpression, decoratorType,
                lifestyle, container);

            registration.ReplaceRelationships(decoratorRelationships ?? Enumerable.Empty<KnownRelationship>());

            var producer = new InstanceProducer(this.registeredServiceType, registration);

            this.appliedDecorators.Add(new DecoratorInfo(decoratorType, producer));
        }
        internal bool SatisfiesPredicate()
        {
            // We don't have an expression at this point, since the instances are not created by the container.
            // Therefore we fake an expression so it can still be passed on to the predicate the user might
            // have defined.
            var expression = Expression.Constant(null, this.registeredServiceType);

            var registration = new ExpressionRegistration(expression, this.registeredServiceType,
                Lifestyle.Unknown, this.Container);

            registration.ReplaceRelationships(this.e.InstanceProducer.GetRelationships());

            this.Context = this.CreatePredicateContext(this.e.InstanceProducer, registration,
                this.registeredServiceType, expression);

            return this.SatisfiesPredicate(this.Context);
        }
        internal void ApplyDecorator()
        {
            var registration = new ExpressionRegistration(this.e.Expression, this.registeredServiceType,
                Lifestyle.Unknown, this.Container);

            registration.ReplaceRelationships(this.e.InstanceProducer.GetRelationships());

            var serviceTypeInfo = this.GetServiceTypeInfo(this.e.Expression, this.e.InstanceProducer,
                registration, this.registeredServiceType);

            Registration decoratorRegistration;

            var decoratedExpression = this.BuildDecoratorExpression(out decoratorRegistration);

            this.e.Expression = decoratedExpression;

            // Add the decorator to the list of applied decorator. This way users can use this
            // information in the predicate of the next decorator they add.
            serviceTypeInfo.AddAppliedDecorator(this.registeredServiceType, this.decoratorType, 
                this.Container, this.Lifestyle, decoratedExpression);

            this.e.KnownRelationships.AddRange(decoratorRegistration.GetRelationships());
        }
コード例 #4
0
        protected InstanceProducer CreateDecorateeFactoryProducer(ParameterInfo parameter)
        {
            // We create a dummy expression with a null value. Much easier than passing on the real delegate.
            // We won't miss it, since the created InstanceProducer is just a dummy for purposes of analysis.
            var dummyExpression = Expression.Constant(null, parameter.ParameterType);

            var registration = new ExpressionRegistration(dummyExpression, this.Container);

            return new InstanceProducer(parameter.ParameterType, registration);
        }
コード例 #5
0
        private static InitializationContext CreateDummyInitializationContext()
        {
            var registration = new ExpressionRegistration(Expression.Constant(null), new Container());

            return new InitializationContext(new InstanceProducer(typeof(object), registration), registration);
        }