public static Tenant GetOrCreate(string tenancy)
        {
            Tenant tenant;

            try
            {
                var config    = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Safe);
                var defaultDb = config[CommonConfiguration.DefaultDataDatabase];

                if (Catalog.Factory.CanResolve <ITenantCreationLicense>())
                {
                    var licenseChecker = Catalog.Factory.Resolve <ITenantCreationLicense>();
                    licenseChecker.CheckTenantCreationLicensed();
                }

                if (defaultDb.Equals(tenancy))
                {
                    throw new ApplicationException("A tenancy cannot use the same db name as the core db");
                }

                var ravenServer = config[CommonConfiguration.DefaultDataConnection];
                var dbName      = tenancy;
                var user        = config[CommonConfiguration.DefaultDataUser];
                var pass        = config[CommonConfiguration.DefaultDataPassword];

                var site = String.Format(TenantConstants.RouteFormat, UnikContextTypes.UnikTenantContextResourceKind,
                                         tenancy);
                var id = String.Format(TenantConstants.TenantIdFormat, tenancy);

                tenant = new TenantManager().GetOrCreate(tenancy, site, id);
                if (tenant == null)
                {
                    return(null);
                }

                DocumentStoreLocator.AddRoute(new Uri(site), ravenServer, dbName, user, pass, tenancy);

                var warehouseRoute = String.Format(TenantConstants.RouteFormat,
                                                   UnikContextTypes.UnikWarehouseContextResourceKind, tenancy);

                DocumentStoreLocator.AddRoute(
                    new Uri(warehouseRoute), ravenServer, String.Format(TenantConstants.WarehouseDbFormatName, dbName),
                    user, pass, tenancy);

                //raise an event on tenant created
                //then the caller can create indexes or any other actions
                OnTenantCreated(site, tenancy);
            }
            catch (LicenseException lex)
            {
                Log.ErrorFormat("An exception occurred with the following message: {0}", lex.Message);
                ApplicationAlert.RaiseAlert(ApplicationAlertKind.System, lex.TraceInformation());

                // Pass along info that tenant creation failed due to license exception.

                throw;
            }
            catch (Exception exception)
            {
                Log.ErrorFormat("An exception occurred with the following message: {0}", exception.Message);
                ApplicationAlert.RaiseAlert(ApplicationAlertKind.System, exception.TraceInformation());
                return(null);
            }

            return(tenant);
        }