/// <summary>
        /// Close the underlying shared connection.
        /// </summary>
        /// <remarks>
        /// The provider of this ConnectionFactory needs to care for proper shutdown.
        /// As this bean implements IDisposable, the application context will
        /// automatically invoke this on destruction of its cached singletons.
        /// </remarks>
        public virtual void Dispose()
        {
            lock (this.connectionMonitor)
            {
                if (this.connection != null)
                {
                    #region Logging
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug("Closing shared RabbitMQ Connection: " + this.connection);
                    }
                    #endregion

                    try
                    {
                        this.connection.Close();
                        this.connection.Dispose();
                    }
                    catch (Exception ex)
                    {
                        logger.Warn("Could not close shared RabbitMQ connection.", ex);
                    }
                }

                this.connection = null;
            }
            Reset();
        }
        /// <summary>
        /// Create a connection.
        /// </summary>
        /// <returns>
        /// The connection.
        /// </returns>
        public IConnection CreateConnection()
        {
            lock (this.connectionMonitor)
            {
                if (this.connection == null)
                {
                    var target = this.DoCreateConnection();
                    this.connection = new SharedConnectionProxy(target, this.listener, this);

                    // invoke the listener *after* this.connection is assigned
                    this.listener.OnCreate(target);
                }
            }

            return this.connection;
        }