Open Closed

Set Tenant connection with current Saas Module in code #5806


User avatar
0
Payoff created

How is it possible to create a new tenant using current form and setting the default connection string programmatically, so as to not expose this information externally? One example could be to use the tenant's name and append it to the current database name. Is this easily doable without re-writing the code for SaaS?

Thank you.

  • ABP Framework version: v7.3.3
  • UI Type: Angular
  • Database System: EF Core (PostgreSQL)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You have to do this manually. This is no built-in way.

    You can download the saas module source code to check the logic.

    Please feel free to add your comments. Thanks

  • User Avatar
    0
    Payoff created

    Is it possible to override an AppService and modify its logic without rewriting the entire module? This way, there's no need to modify the form, but all the work can be done on the backend Thank you.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Is it possible to override an AppService and modify its logic without rewriting the entire module?

    Yes, of course you can, for example:

    [ExposeServices(typeof(ITenantAppService))]
    [Dependency(ReplaceServices = true)]
    public class MyTenantAppService : TenantAppService
    {
        public MyTenantAppService(ITenantRepository tenantRepository, IEditionRepository editionRepository, ITenantManager tenantManager, IDataSeeder dataSeeder, IDistributedEventBus distributedEventBus, IOptions<AbpDbConnectionOptions> dbConnectionOptions, IConnectionStringChecker connectionStringChecker) : base(tenantRepository, editionRepository, tenantManager, dataSeeder, distributedEventBus, dbConnectionOptions, connectionStringChecker)
        {
        }
    
        public override Task<SaasTenantDto> CreateAsync(SaasTenantCreateDto input)
        {
            input.ConnectionStrings = new SaasTenantConnectionStringsDto
            {
                Databases = new List<SaasTenantDatabaseConnectionStringsDto>
                {
                    new SaasTenantDatabaseConnectionStringsDto {
                        ConnectionString = "...",
                        DatabaseName = "Default"
                    }
                }
            };
            return base.CreateAsync(input);
        }
    }
    
Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11