// This method will be inlined by the JIT.
 // Resets the validator to its initial state. This is important when a IInstanceProvider threw an
 // exception, because a new call to that provider would otherwise make the validator think it is a
 // recursive call and throw an exception, and this would hide the exception that would otherwise be
 // thrown by the provider itself.
 internal static void Reset(this CyclicDependencyValidator validator)
 {
     if (validator != null)
     {
         validator.RollBack();
     }
 }
 internal static void CheckForRecursiveCalls(this CyclicDependencyValidator validator)
 {
     if (validator != null)
     {
         validator.Check();
     }
 }
        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);
            }
        }
 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;
     }
 }
        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(registration.ImplementationType);

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

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

            this.instanceCreator = this.BuildAndReplaceInstanceCreatorAndCreateFirstInstance;
        }