Support forum for ASP.NET Zero (https://aspnetzero.com/).
By MikaTmlVertti
#29914 Hi
I need to add azure storage connection string for every tenant, if default is not used. So basically same functions as db connection string. Could you provide me some directions how to handle this.

1. Add storage connection string to Tenant entity
2. Get that connection string when needed, or if not exist, get default.

Mika
By ismcagdas
#29919 Hi @MikaTmlVertti,

Here are the related classes for getting a connection string for the current tenant (or host).

https://github.com/aspnetboilerplate/as ... esolver.cs
https://github.com/aspnetboilerplate/as ... esolver.cs

So, you can create a similar interface and it's implementation and use it in your project.
By ismcagdas
#29978 You can use CustomData attribute of TenantCacheItem. In order to do that, create a class deriving from TenantCache;

Code: Select allpublic class MyTenantaCache : TenantCache<Tenant, User>
{
   public MyTenantaCache(
      ICacheManager cacheManager,
      IRepository<Tenant> tenantRepository,
      IUnitOfWorkManager unitOfWorkManager) : base(cacheManager, tenantRepository, unitOfWorkManager)
   {
   }

   protected override TenantCacheItem CreateTenantCacheItem(Tenant tenant)
   {
      return new TenantCacheItem
      {
         Id = tenant.Id,
         Name = tenant.Name,
         TenancyName = tenant.TenancyName,
         EditionId = tenant.EditionId,
         ConnectionString = SimpleStringCipher.Instance.Decrypt(tenant.ConnectionString),
         IsActive = tenant.IsActive,
         CustomData = tenant.azureConnStr
      };
   }
}


Then, you can register this class in the Initialize method of your module;

Code: Select allIocManager.Register<ITenantCache, MyTenantCache>(DependencyLifeStyle.Transient);
By MikaTmlVertti
#29995 I made TenantaCacheExtended:
Code: Select all public class TenantaCacheExtended : TenantCache<Tenant, User>
    {
        public TenantaCacheExtended(
           ICacheManager cacheManager,
           IRepository<Tenant> tenantRepository,
           IUnitOfWorkManager unitOfWorkManager) : base(cacheManager, tenantRepository, unitOfWorkManager)
        {
        }

        protected override TenantCacheItem CreateTenantCacheItem(Tenant tenant)
        {
            return new TenantCacheItem
            {
                Id = tenant.Id,
                Name = tenant.Name,
                TenancyName = tenant.TenancyName,
                EditionId = tenant.EditionId,
                ConnectionString = SimpleStringCipher.Instance.Decrypt(tenant.ConnectionString),
                IsActive = tenant.IsActive,
                CustomData = SimpleStringCipher.Instance.Decrypt(tenant.AzureStorageConnectionString),
            };
        }
    }

and it is located in Core project, same place where Tenant class is.

I tried to add IocManager.Register<ITenantCache, TenantaCacheExtended>(DependencyLifeStyle.Transient);
to Core modules Initialize, PostInitialize and finally Application modules Initialize methods, but class is not being used. I had breakpoint at line "return new TenantCacheItem" but it newer got fired.

At the method where this custom data is supposed to be read, it is null.

Any advise?
By MikaTmlVertti
#30001
alper wrote:I think you need to replace the service with the code like below.


I tried again in Core module Initialize and PostInitialize and Application module Initialize but it didn't work. Where do you think I need to add that Replace method?
By MikaTmlVertti
#30029 First without ReplaceService, then both Register and Replace and lastly only Replace.

Code: Select allpublic override void Initialize()
{
    IocManager.RegisterAssemblyByConvention(typeof('my'ApplicationModule).GetAssembly());
   
    IocManager.Register<ITenantCache, TenantaCacheExtended>(DependencyLifeStyle.Transient);
    Configuration.ReplaceService<ITenantCache, TenantaCacheExtended>(DependencyLifeStyle.Transient);
}


And this is in public class 'my'ApplicationModule : AbpModule.
By MikaTmlVertti
#30031 Started playing with settings and now I inserted those two lines to PreInitialize() and got exeption that there is allready class defined as ITenantCache. Removed Register and left only Replace -> my TenantCacheExtended CreateTenantCacheItem is being used.

So Not Initialize() but PreInitialize().