Created tenant setting value provider.

pull/204/head
Halil İbrahim Kalkan 7 years ago
parent 008f42f08f
commit 169d019f7d

@ -16,6 +16,7 @@
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
<ProjectReference Include="..\Volo.Abp.Data\Volo.Abp.Data.csproj" />
<ProjectReference Include="..\Volo.Abp.Settings\Volo.Abp.Settings.csproj" />
</ItemGroup>
</Project>

@ -1,14 +1,21 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
using Volo.Abp.Settings;
namespace Volo.Abp.MultiTenancy
{
[DependsOn(typeof(AbpDataModule))]
[DependsOn(typeof(AbpSettingsModule))]
public class AbpMultiTenancyAbstractionsModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.Configure<SettingOptions>(options =>
{
options.ValueProviders.Add<TenantSettingValueProvider>();
});
services.AddAssemblyOf<AbpMultiTenancyAbstractionsModule>();
}
}

@ -0,0 +1,45 @@
using System.Threading.Tasks;
using Volo.Abp.Settings;
namespace Volo.Abp.MultiTenancy
{
public class TenantSettingValueProvider : SettingValueProvider
{
public const string ProviderName = "Tenant";
public override string Name => ProviderName;
protected ICurrentTenant CurrentTenant { get; }
public TenantSettingValueProvider(ISettingStore settingStore, ICurrentTenant currentTenant)
: base(settingStore)
{
CurrentTenant = currentTenant;
}
public override async Task<string> GetOrNullAsync(SettingDefinition setting, string providerKey)
{
if (providerKey == null)
{
if (CurrentTenant.Id == null)
{
return null;
}
providerKey = CurrentTenant.Id.ToString();
}
return await SettingStore.GetOrNullAsync(setting.Name, Name, providerKey);
}
public override Task SetAsync(SettingDefinition setting, string value, string providerKey)
{
return SettingStore.SetAsync(setting.Name, value, Name, providerKey);
}
public override Task ClearAsync(SettingDefinition setting, string providerKey)
{
return SettingStore.DeleteAsync(setting.Name, Name, providerKey);
}
}
}

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Settings
{
public static class TenantSettingManagerExtensions
{
public static Task<string> GetOrNullForTenantAsync(this ISettingManager settingManager, [NotNull] string name, Guid tenantId, bool fallback = true)
{
return settingManager.GetOrNullAsync(name, TenantSettingValueProvider.ProviderName, tenantId.ToString(), fallback);
}
public static Task<string> GetOrNullForCurrentTenantAsync(this ISettingManager settingManager, [NotNull] string name, bool fallback = true)
{
return settingManager.GetOrNullAsync(name, TenantSettingValueProvider.ProviderName, null, fallback);
}
public static Task<List<SettingValue>> GetAllForTenantAsync(this ISettingManager settingManager, Guid tenantId, bool fallback = true)
{
return settingManager.GetAllAsync(TenantSettingValueProvider.ProviderName, tenantId.ToString(), fallback);
}
public static Task<List<SettingValue>> GetAllForCurrentTenantAsync(this ISettingManager settingManager, bool fallback = true)
{
return settingManager.GetAllAsync(TenantSettingValueProvider.ProviderName, null, fallback);
}
public static Task SetForTenantAsync(this ISettingManager settingManager, Guid tenantId, [NotNull] string name, [CanBeNull] string value, bool forceToSet = false)
{
return settingManager.SetAsync(name, value, TenantSettingValueProvider.ProviderName, tenantId.ToString(), forceToSet);
}
public static Task SetForCurrentTenantAsync(this ISettingManager settingManager, [NotNull] string name, [CanBeNull] string value, bool forceToSet = false)
{
return settingManager.SetAsync(name, value, TenantSettingValueProvider.ProviderName, null, forceToSet);
}
}
}
Loading…
Cancel
Save