// We're registering a service type after 'locking down' the container here and that means that the
        // type is added to a copy of the registrations dictionary and the original replaced with a new one.
        // This 'reference swapping' is thread-safe, but can result in types disappearing again from the
        // registrations when multiple threads simultaneously add different types. This however, does not
        // result in a consistency problem, because the missing type will be again added later. This type of
        // swapping safes us from using locks.
        private void AppendRootInstanceProducer(Type serviceType, InstanceProducer?rootProducer)
        {
            Helpers.InterlockedAddAndReplace(ref this.rootProducerCache, serviceType, rootProducer);

            if (rootProducer != null)
            {
                this.RemoveExternalProducer(rootProducer);
            }
        }