Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

[AbpSession] change TenantId on the fly in console app #1419


User avatar
0
daws created

Hello,

I have a console which runs multiple operations on multiple database.

rather than use SetTenantId in the Manager (too much change, don't match with my app logic), i would like to modify the IAbpSession on the fly to use the UnitOfWork with the correct database.

Right now (based on your sample), I ovveride the AbpSession in the PreInitialize of my module. Can i replace it anywhere in my code, and how ?

[DependsOn(typeof (SSSSDataModule), typeof (SSSSApplicationModule))]
    public class SSSSSServerAppModule : AbpModule
    {
        public override void PreInitialize()
        {
            //Suppress authentication and permission checking for the application, register as tenant configured in app.config
            IocManager.Register<IAbpSession, TenantAppSession>();
            IocManager.Register<IPermissionChecker, NullPermissionChecker>();
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }
    }

thanks for your help !


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Your code seems OK. But note that: Filter value is retrieved from session when you first use a db connection. So, in a unit of work, if you perform one db operation, then set tenantid in the session, it will not set the filter value. But if you set it before UOW begins, it will work. Only way of changing TenantId in a UOW is to use SetTenantId.