コード例 #1
0
 // Flagging the registration with WrapsInstanceCreationDelegate prevents false diagnostic warnings.
 private InstanceProducer(Type serviceType, Expression expression, Container container)
     : this(serviceType,
            new ExpressionRegistration(expression, container) { WrapsInstanceCreationDelegate = true })
 {
     // Overrides earlier set value. This prevents ExpressionBuilt from being applied.
     this.lazyExpression = Helpers.ToLazy(expression);
 }
コード例 #2
0
        private InstanceProducer TryGetProducerFromUnregisteredTypeResolutionCacheOrAdd(
            UnregisteredTypeEventArgs e)
        {
            lock (this.resolveUnregisteredTypeRegistrations)
            {
                if (this.resolveUnregisteredTypeRegistrations.ContainsKey(e.UnregisteredServiceType))
                {
                    // This line will only get hit, in case a different thread came here first.
                    return(this.resolveUnregisteredTypeRegistrations[e.UnregisteredServiceType].Value);
                }

                var registration = e.Registration ?? new ExpressionRegistration(e.Expression, this);

                // By creating the InstanceProducer after checking the dictionary, we prevent the producer
                // from being created twice when multiple threads are running. Having the same duplicate
                // producer can cause a torn lifestyle warning in the container.
                var producer = new InstanceProducer(e.UnregisteredServiceType, registration);

                this.resolveUnregisteredTypeRegistrations[e.UnregisteredServiceType] =
                    Helpers.ToLazy(producer);

                return(producer);
            }
        }