Пример #1
0
 private void RemoveValidator()
 {
     // No recursive calls detected, we can remove the validator to increase performance.
     // We first check for null, because this is faster. Every time we write, the CPU has to send
     // the new value to all the other CPUs. We only nullify the validator while using the GetInstance
     // method, because the BuildExpression will only be called a limited amount of time.
     if (this.validator != null)
     {
         this.validator = null;
     }
 }
Пример #2
0
        internal InstanceProducer(Type serviceType, Registration registration, bool registerExternalProducer)
        {
            Requires.IsNotNull(serviceType, "serviceType");
            Requires.IsNotNull(registration, "registration");

            this.ServiceType  = serviceType;
            this.Registration = registration;
            this.validator    = new CyclicDependencyValidator(registration.ImplementationType);

            this.lazyExpression        = new Lazy <Expression>(this.BuildExpressionInternal);
            this.initializationContext = new InitializationContext(this, registration);

            if (registerExternalProducer)
            {
                registration.Container.RegisterExternalProducer(this);
            }
        }
        internal InstanceProducer(Type serviceType, Registration registration, bool registerExternalProducer)
        {
            Requires.IsNotNull(serviceType, nameof(serviceType));
            Requires.IsNotNull(registration, nameof(registration));
            Requires.IsNotOpenGenericType(serviceType, nameof(serviceType));

            this.ServiceType  = serviceType;
            this.Registration = registration;
            this.validator    = new CyclicDependencyValidator(this);

            this.lazyExpression = new LazyEx <Expression>(this.BuildExpressionInternal);

            if (registerExternalProducer)
            {
                registration.Container.RegisterExternalProducer(this);
            }

            this.instanceCreator = this.BuildAndReplaceInstanceCreatorAndCreateFirstInstance;
        }
Пример #4
0
        /// <summary>Initializes a new instance of the <see cref="InstanceProducer"/> class.</summary>
        /// <param name="serviceType">The service type for which this instance is created.</param>
        /// <param name="registration">The <see cref="Registration"/>.</param>
        public InstanceProducer(Type serviceType, Registration registration)
        {
            Requires.IsNotNull(serviceType, "serviceType");
            Requires.IsNotNull(registration, "registration");

            this.ServiceType  = serviceType;
            this.Registration = registration;

            this.validator = new CyclicDependencyValidator(registration.ImplementationType);

            this.expression = new Lazy <Expression>(this.BuildExpressionInternal);

            // ExpressionRegistration is an internal Registration type. An InstanceProducer with this type
            // of registration doesn't have to be registered, since it will either always be registered
            // in the registrations dictionary anyway, or it is used to build up an InstanceProducer (by
            // the decorator sub system) that is only used for diagnostics. Allowing the latter producers to
            // be added, will clutter the diagnostic API and will cause the Verify() method to verify those
            // producers needlessly.
            if (!(registration is ExpressionRegistration))
            {
                registration.Container.RegisterExternalProducer(this);
            }
        }