Open Closed

Breaking change in ABP Upgrade from 7.4.2 to 9.1.0 #8981


User avatar
0
balessi75 created

ABP Commercial 9.1.0 / Blazor Server / EF / Non tiered / Separate Host and Tenant DBs / Lepton Theme

In version 7.4.2, we relied on an override to AppUrlProvider to support subdomain base multi-tenancy. Our override was on the ReplacePlaceHoldersAsync method which appears to no longer be available in abp 9.1.0. Please see our override in ABP 7.4.2 and advise on how to accomplish this in ABP 9.1.0.

using JetBrains.Annotations;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Account;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
using Volo.Abp.UI.Navigation.Urls;
using Microsoft.Extensions.Localization;
using Volo.Abp.Sms;
using Microsoft.Extensions.Options;
using FM.nVision.Saas;
using Volo.Abp.Features;

namespace FM.nVision.Account
{
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IAppUrlProvider), typeof(AppUrlProvider), typeof(ITransientDependency))]
    [RequiresFeature(SaasConsts.nVisionFeature, SaasConsts.TimepieceFeature)]
    [RemoteService(IsEnabled = false)]
    public class nVisionAppUrlProvider : AppUrlProvider
    {
        public const string TenantSubdomainPlaceHolder = "{{subdomain}}";

        IFMTenantRepository _fmTenantRepository { get; set; }    

        public nVisionAppUrlProvider(
            IOptions<AppUrlOptions> options,
            ICurrentTenant currentTenant,
            ITenantStore tenantStore,
            IFMTenantRepository fmTenantRepository) : base(options, currentTenant, tenantStore)
        {
            _fmTenantRepository = fmTenantRepository;
        }

        protected override async Task<string> ReplacePlaceHoldersAsync(string url)
        {
            url = await base.ReplacePlaceHoldersAsync(url);

            var tenantSubdomainPlaceHolder = TenantSubdomainPlaceHolder;

            if (url.Contains(TenantSubdomainPlaceHolder + '.'))
            {
                tenantSubdomainPlaceHolder = TenantSubdomainPlaceHolder + '.';
            }

            if (url.Contains(tenantSubdomainPlaceHolder))
            {
                if (CurrentTenant.Id.HasValue)
                {
                    var subdomain = await GetCurrentTenantSubdomainAsync();
                    if (!subdomain.IsNullOrWhiteSpace()) 
                    {
                        url = url.Replace(tenantSubdomainPlaceHolder, subdomain + ".");
                    }
                    else
                    {
                        url = url.Replace(tenantSubdomainPlaceHolder, "");
                    }               
                }
                else
                {
                    url = url.Replace(tenantSubdomainPlaceHolder, "");
                }
            }

            return url;
        }

        private async Task<string> GetCurrentTenantSubdomainAsync()
        {
            if (CurrentTenant.Id.HasValue)
            {
                return await _fmTenantRepository.GetSubdomainByTenantIdAsync(CurrentTenant.Id.Value);
            }

            return string.Empty;
        }   
    }
}

1 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi,

    ABP now supports this feature by default. See more: https://github.com/abpframework/abp/pull/18592

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on April 16, 2025, 12:13