Starts in:
2 DAYS
0 HR
46 MIN
26 SEC
Starts in:
2 D
0 H
46 M
26 S

Activities of "Spospisil"

[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IConnectionStringResolver))]
public class SWMultiTenantConnectionStringResolver : MultiTenantConnectionStringResolver
{
    private readonly ICurrentTenant _currentTenant;
    private readonly IServiceProvider _serviceProvider;

    public SWMultiTenantConnectionStringResolver(
        IOptionsSnapshot<AbpDbConnectionOptions> options,
        ICurrentTenant currentTenant,
        IServiceProvider serviceProvider) : base(options, currentTenant, serviceProvider)
    {
        _currentTenant = currentTenant;
        _serviceProvider = serviceProvider;
    }

    public override async Task<string> ResolveAsync(string connectionStringName = null)
    {
        string connectionstring = "";

        //No current tenant, fallback to default logic
        if (_currentTenant.Id == null)
        {
            return await base.ResolveAsync(connectionStringName);
        }


        if (_currentTenant.IsAvailable)
        {
            switch (connectionStringName)
            {
                case LanguageManagementDbProperties.ConnectionStringName:
                case AbpPermissionManagementDbProperties.ConnectionStringName:
                case FeatureManagementDbProperties.ConnectionStringName:
                    using (_currentTenant.Change(null))
                    {
                        connectionstring = await base.ResolveAsync(connectionStringName);
                    }
                    break;

                case "Volo.Abp.Identity.EntityFrameworkCore.IIdentityProDbContext":
                    using (_currentTenant.Change(null))
                    {
                        connectionstring = await base.ResolveAsync(connectionStringName);
                    }
                    break;

                case "Default":
                    using (_currentTenant.Change(null))
                    {
                        connectionstring = await base.ResolveAsync(connectionStringName);
                    }
                    break;

                default:
                    var tenant = await FindTenantConfigurationAsync(_currentTenant.Id.Value);

                    if (tenant == null || tenant.ConnectionStrings.IsNullOrEmpty())
                    {
                        //Tenant has not defined any connection string, fallback to default logic
                        return await base.ResolveAsync(connectionStringName);
                    }

                    connectionstring = tenant.ConnectionStrings.Default;
                    break;
            }
        }

        //Replace with the following code when 5.0 is released
        //if (connectionStringName == AbpIdentityDbProperties.ConnectionStringName)
        //{
        //    //.. return host's connection string
        //}
        return await Task.FromResult(connectionstring);
    }
}

What specifically in the code do you need to see?

That is correct, you did not suggest that you did recomend that approach but if you read the entire thread it was suggested by someone else at Volo and did resolve that issue, so it appears that the connectionstring naming is not consistant so I will have to accomodate for that however, the issue is still not resolved with the LanguageTexts error I indicated I am getting which only happens when I log in as a Tenant user. Host user works fine. Please read thread to understand the distribution of our host vs tenant tables.

Thanks.

Hi,

But it's been suggested here that I not use the connection name string, but rather use the full namespace and Interface class name to resolve this issue.

So how do I resolve the issue I'm getting as I've tried everything that's been suggested with no success.

That resolved the issue with the code not finding the Users table but now I get an error on the "LanguageTexts" table as shown below. Just to clarify all the ABP base tables, including Saas, Identity server, users, etc are in a 'host' DB and the only tables in the 'tenant' DB are our application specific tables. So I want all things ABP module(pro and otherwise) to look at the host DB.

I tried adding the following code to resolve that connection string, but it did not work,.

                case "Volo.Abp.LanguageManagement.EntityFrameworkCore.ILanguageManagementDbContext":
                    using (_currentTenant.Change(null))
                    {
                        connectionstring = await base.ResolveAsync(connectionStringName);
                    }
                    break;

After looking at this deeper, what you suggested as the solution is not accurate. The 'connectionstringname' that is being used by the MultiTenantConnectionStringResolver are not the value you suggest, thus making it difficult to point each (if I choose to) module's DBContext to a particular connection string.

So to summarize I am trying to put all the ABP tables that store Identity, LanguageManagement, permissions, Auditing, users, etc into the Host's DB and just have tennat tables (application specific) in their own DB's for each tenant.

There is no clear direction in the documents or previous support tickets that outline this so an actual real world example of this being implemented using ABP would be much appreaciated.

Thank you. That resolves my issue

@gterdem

Is there a way to programitically set the abp.apppath?

Any update for this?

By the way, when I log in as a Host user I do not get an error. It's only when I log in as a Tenant user.

Showing 171 to 180 of 208 entries
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06