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, originalRegistration: registration, registeredServiceType: this.registeredServiceType); var decoratedExpression = this.BuildDecoratorExpression(out Registration 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()); }
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)); }
protected ServiceTypeDecoratorInfo GetServiceTypeInfo(Expression originalExpression, InstanceProducer registeredProducer, Type registeredServiceType, Lifestyle lifestyle) { // registeredProducer.ServiceType and registeredServiceType are different when called by // container uncontrolled decorator. producer.ServiceType will be IEnumerable<T> and // registeredServiceType will be T. Func <Type, InstanceProducer> producerBuilder = implementationType => { // The InstanceProducer created here is used to do correct diagnostics. We can't return the // registeredProducer here, since the lifestyle of the original producer can change after // the ExpressionBuilt event has ran, which means that this would invalidate the diagnostic // results. var registration = new ExpressionRegistration(originalExpression, implementationType, lifestyle, this.Container); registration.ReplaceRelationships(registeredProducer.GetRelationships()); return(new InstanceProducer(registeredServiceType, registration)); }; return(this.GetServiceTypeInfo(originalExpression, registeredProducer, producerBuilder)); }