ServiceStack.ServiceStackHost.GetDbConnection C# (CSharp) Method

GetDbConnection() public method

Gets IDbConnection Checks if DbInfo is seat in RequestContext. See multitenancy: https://github.com/ServiceStack/ServiceStack/wiki/Multitenancy Called by itself, and
public GetDbConnection ( IRequest req = null ) : IDbConnection
req IRequest Provided by services and pageView, can be helpfull when overriding this method
return IDbConnection
        public virtual IDbConnection GetDbConnection(IRequest req = null)
        {
            var dbFactory = Container.TryResolve<IDbConnectionFactory>();

            ConnectionInfo connInfo;
            if (req != null && (connInfo = req.GetItem(Keywords.DbInfo) as ConnectionInfo) != null)
            {
                var dbFactoryExtended = dbFactory as IDbConnectionFactoryExtended;
                if (dbFactoryExtended == null)
                    throw new NotSupportedException("ConnectionInfo can only be used with IDbConnectionFactoryExtended");

                if (connInfo.ConnectionString != null && connInfo.ProviderName != null)
                    return dbFactoryExtended.OpenDbConnectionString(connInfo.ConnectionString, connInfo.ProviderName);

                if (connInfo.ConnectionString != null)
                    return dbFactoryExtended.OpenDbConnectionString(connInfo.ConnectionString);

                if (connInfo.NamedConnection != null)
                    return dbFactoryExtended.OpenDbConnection(connInfo.NamedConnection);
            }

            return dbFactory.OpenDbConnection();
        }