diff --git a/Volo.Abp.sln b/Volo.Abp.sln index 259de7b7cf..f94fa81e50 100644 --- a/Volo.Abp.sln +++ b/Volo.Abp.sln @@ -244,7 +244,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.MultiTenancy.Appli EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.MultiTenancy.Web", "src\Volo.Abp.MultiTenancy.Web\Volo.Abp.MultiTenancy.Web.csproj", "{0808036D-065B-4525-BF30-CBCEA062F8E9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.MultiTenancy.HttpApi", "src\Volo.Abp.MultiTenancy.HttpApi\Volo.Abp.MultiTenancy.HttpApi.csproj", "{06423FAC-67E2-4B7C-B29F-39578F460C4F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.MultiTenancy.HttpApi", "src\Volo.Abp.MultiTenancy.HttpApi\Volo.Abp.MultiTenancy.HttpApi.csproj", "{06423FAC-67E2-4B7C-B29F-39578F460C4F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Settings", "src\Volo.Abp.Settings\Volo.Abp.Settings.csproj", "{CB6FD800-B6C5-4C2A-8920-B8A29C74AEF6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Settings.EntityFrameworkCore", "src\Volo.Abp.Settings.EntityFrameworkCore\Volo.Abp.Settings.EntityFrameworkCore.csproj", "{1DCD9600-215A-4A94-AEFD-577568D62633}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Settings.Domain", "src\Volo.Abp.Settings.Domain\Volo.Abp.Settings.Domain.csproj", "{837BC537-3AEC-4F6D-9D64-9704F64D0E1E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -640,6 +646,18 @@ Global {06423FAC-67E2-4B7C-B29F-39578F460C4F}.Debug|Any CPU.Build.0 = Debug|Any CPU {06423FAC-67E2-4B7C-B29F-39578F460C4F}.Release|Any CPU.ActiveCfg = Release|Any CPU {06423FAC-67E2-4B7C-B29F-39578F460C4F}.Release|Any CPU.Build.0 = Release|Any CPU + {CB6FD800-B6C5-4C2A-8920-B8A29C74AEF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CB6FD800-B6C5-4C2A-8920-B8A29C74AEF6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CB6FD800-B6C5-4C2A-8920-B8A29C74AEF6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CB6FD800-B6C5-4C2A-8920-B8A29C74AEF6}.Release|Any CPU.Build.0 = Release|Any CPU + {1DCD9600-215A-4A94-AEFD-577568D62633}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1DCD9600-215A-4A94-AEFD-577568D62633}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1DCD9600-215A-4A94-AEFD-577568D62633}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1DCD9600-215A-4A94-AEFD-577568D62633}.Release|Any CPU.Build.0 = Release|Any CPU + {837BC537-3AEC-4F6D-9D64-9704F64D0E1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {837BC537-3AEC-4F6D-9D64-9704F64D0E1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {837BC537-3AEC-4F6D-9D64-9704F64D0E1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {837BC537-3AEC-4F6D-9D64-9704F64D0E1E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -759,6 +777,9 @@ Global {B65973F1-9EE0-4914-B6F2-D88F753E1D21} = {3CE22CAC-4B27-4EEC-A35E-C01219ED6E99} {0808036D-065B-4525-BF30-CBCEA062F8E9} = {CA154803-3589-47B3-B7CB-B18F94FE1EB6} {06423FAC-67E2-4B7C-B29F-39578F460C4F} = {CA154803-3589-47B3-B7CB-B18F94FE1EB6} + {CB6FD800-B6C5-4C2A-8920-B8A29C74AEF6} = {4C753F64-0C93-4D65-96C2-A40893AFC1E8} + {1DCD9600-215A-4A94-AEFD-577568D62633} = {4C753F64-0C93-4D65-96C2-A40893AFC1E8} + {837BC537-3AEC-4F6D-9D64-9704F64D0E1E} = {4C753F64-0C93-4D65-96C2-A40893AFC1E8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskDbContext.cs b/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskDbContext.cs index e53b60966f..8a583e93f2 100644 --- a/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskDbContext.cs +++ b/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskDbContext.cs @@ -26,7 +26,7 @@ namespace AbpDesk.EntityFrameworkCore { base.OnModelCreating(modelBuilder); - modelBuilder.ConfigureMultiTenancy(MultiTenancyDbContext.TablePrefix, MultiTenancyDbContext.Schema); + modelBuilder.ConfigureMultiTenancy(); //Use different classes to map each entity type, as a better practice? modelBuilder.Entity(b => diff --git a/src/Volo.Abp.Ddd/Volo/Abp/AbpServiceBase.cs b/src/Volo.Abp.Ddd/Volo/Abp/AbpServiceBase.cs index 7911c7a366..01b7aecaf1 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/AbpServiceBase.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/AbpServiceBase.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Guids; +using Volo.Abp.MultiTenancy; using Volo.Abp.ObjectMapping; using Volo.Abp.Uow; @@ -17,6 +18,8 @@ namespace Volo.Abp public ILoggerFactory LoggerFactory { get; set; } + public ICurrentTenant CurrentTenant { get; set; } + protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current; protected ILogger Logger => _lazyLogger.Value; diff --git a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerEntityFrameworkCoreModule.cs b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerEntityFrameworkCoreModule.cs index e7c787a206..9594451956 100644 --- a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerEntityFrameworkCoreModule.cs +++ b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerEntityFrameworkCoreModule.cs @@ -1,6 +1,9 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.Clients; +using Volo.Abp.IdentityServer.Grants; +using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.Modularity; namespace Volo.Abp.IdentityServer.EntityFrameworkCore @@ -14,7 +17,11 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore services.AddAbpDbContext(options => { options.AddDefaultRepositories(); + options.AddRepository(); + options.AddRepository(); + options.AddRepository(); + options.AddRepository(); }); services.AddAssemblyOf(); diff --git a/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/CurrentTenant.cs b/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/CurrentTenant.cs index 1cee215eea..743355d415 100644 --- a/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/CurrentTenant.cs +++ b/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/CurrentTenant.cs @@ -21,7 +21,7 @@ namespace Volo.Abp.MultiTenancy return SetCurrent(id); } - public IDisposable Clear() + public IDisposable Clear() //TODO: Remove { return Change(null); } diff --git a/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/AbpIdentityConsts.cs b/src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/AbpMultiTenancyConsts.cs similarity index 100% rename from src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/AbpIdentityConsts.cs rename to src/Volo.Abp.MultiTenancy.Domain/Volo/Abp/MultiTenancy/AbpMultiTenancyConsts.cs diff --git a/src/Volo.Abp.Settings.Domain/Volo.Abp.Settings.Domain.csproj b/src/Volo.Abp.Settings.Domain/Volo.Abp.Settings.Domain.csproj new file mode 100644 index 0000000000..2339d7a04c --- /dev/null +++ b/src/Volo.Abp.Settings.Domain/Volo.Abp.Settings.Domain.csproj @@ -0,0 +1,22 @@ + + + + + + netstandard2.0 + Volo.Abp.Settings.Domain + Volo.Abp.Settings.Domain + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + + diff --git a/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/AbpSettingsDomainModule.cs b/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/AbpSettingsDomainModule.cs new file mode 100644 index 0000000000..2c1d5266ac --- /dev/null +++ b/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/AbpSettingsDomainModule.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.Settings +{ + [DependsOn(typeof(AbpSettingsModule))] + [DependsOn(typeof(AbpDddModule))] + [DependsOn(typeof(AbpMultiTenancyAbstractionsModule))] + public class AbpSettingsDomainModule : AbpModule + { + public override void ConfigureServices(IServiceCollection services) + { + services.AddAssemblyOf(); + } + } +} diff --git a/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/ISettingRepository.cs b/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/ISettingRepository.cs new file mode 100644 index 0000000000..7c7164204a --- /dev/null +++ b/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/ISettingRepository.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Settings +{ + public interface ISettingRepository : IBasicRepository + { + Task FindAsync(string name, string entityType, string entityId); + + Task> GetListAsync(string entityType, string entityId); + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/Setting.cs b/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/Setting.cs new file mode 100644 index 0000000000..5db42e473c --- /dev/null +++ b/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/Setting.cs @@ -0,0 +1,48 @@ +using System; +using JetBrains.Annotations; +using Volo.Abp.Domain.Entities; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.Settings +{ + public class Setting : Entity, IMultiTenant + { + public virtual Guid? TenantId { get; protected set; } + + [NotNull] + public virtual string Name { get; protected set; } + + [NotNull] + public virtual string Value { get; internal set; } + + [CanBeNull] + public virtual string EntityType { get; protected set; } + + [CanBeNull] + public virtual string EntityId { get; protected set; } + + protected Setting() + { + + } + + public Setting( + Guid id, + [NotNull] string name, + [NotNull] string value, + [CanBeNull] string entityType = null, + [CanBeNull] string entityId = null, + Guid? tenantId = null) + { + Check.NotNull(name, nameof(name)); + Check.NotNull(value, nameof(value)); + + Id = id; + Name = name; + Value = value; + EntityType = entityType; + EntityId = entityId; + TenantId = tenantId; + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/SettingStore.cs b/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/SettingStore.cs new file mode 100644 index 0000000000..43cf73acce --- /dev/null +++ b/src/Volo.Abp.Settings.Domain/Volo/Abp/Settings/SettingStore.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Settings +{ + public class SettingStore : AbpServiceBase, ISettingStore, ITransientDependency + { + private readonly ISettingRepository _settingRepository; + + public SettingStore(ISettingRepository settingRepository) + { + _settingRepository = settingRepository; + } + + public async Task GetOrNullAsync(string name, string entityType, string entityId) + { + var setting = await _settingRepository.FindAsync(name, entityType, entityId); + return setting?.Value; + } + + public async Task SetAsync(string name, string value, string entityType, string entityId) + { + var setting = await _settingRepository.FindAsync(name, entityType, entityId); + if (setting == null) + { + setting = new Setting(GuidGenerator.Create(), name, value, entityType, entityId, CurrentTenant.Id); + await _settingRepository.InsertAsync(setting); + } + + setting.Value = value; + await _settingRepository.UpdateAsync(setting); + } + + public async Task> GetListAsync(string entityType, string entityId) + { + var setting = await _settingRepository.GetListAsync(entityType, entityId); + return setting.Select(s => new SettingValue(s.Name, s.Value)).ToList(); + } + } +} diff --git a/src/Volo.Abp.Settings.EntityFrameworkCore/Volo.Abp.Settings.EntityFrameworkCore.csproj b/src/Volo.Abp.Settings.EntityFrameworkCore/Volo.Abp.Settings.EntityFrameworkCore.csproj new file mode 100644 index 0000000000..8ca5ce8156 --- /dev/null +++ b/src/Volo.Abp.Settings.EntityFrameworkCore/Volo.Abp.Settings.EntityFrameworkCore.csproj @@ -0,0 +1,21 @@ + + + + + + netstandard2.0 + Volo.Abp.Settings.EntityFrameworkCore + Volo.Abp.Settings.EntityFrameworkCore + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + diff --git a/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/AbpSettingsDbContext.cs b/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/AbpSettingsDbContext.cs new file mode 100644 index 0000000000..19150e366b --- /dev/null +++ b/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/AbpSettingsDbContext.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace Volo.Abp.Settings.EntityFrameworkCore +{ + public class AbpSettingsDbContext : AbpDbContext, IAbpSettingsDbContext + { + public DbSet Settings { get; set; } + + public AbpSettingsDbContext(DbContextOptions options) + : base(options) + { + + } + } +} diff --git a/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/AbpSettingsEntityFrameworkCoreModule.cs b/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/AbpSettingsEntityFrameworkCoreModule.cs new file mode 100644 index 0000000000..8b906f1579 --- /dev/null +++ b/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/AbpSettingsEntityFrameworkCoreModule.cs @@ -0,0 +1,22 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Settings.EntityFrameworkCore +{ + [DependsOn(typeof(AbpSettingsDomainModule))] + [DependsOn(typeof(AbpSettingsEntityFrameworkCoreModule))] + public class AbpSettingsEntityFrameworkCoreModule : AbpModule + { + public override void ConfigureServices(IServiceCollection services) + { + services.AddAbpDbContext(options => + { + options.AddDefaultRepositories(); + + options.AddRepository(); + }); + + services.AddAssemblyOf(); + } + } +} diff --git a/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/EfCoreSettingRepository.cs b/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/EfCoreSettingRepository.cs new file mode 100644 index 0000000000..2073f36269 --- /dev/null +++ b/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/EfCoreSettingRepository.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace Volo.Abp.Settings.EntityFrameworkCore +{ + public class EfCoreSettingRepository : EfCoreRepository, ISettingRepository + { + public EfCoreSettingRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } + + public async Task FindAsync(string name, string entityType, string entityId) + { + return await DbSet.FirstOrDefaultAsync(s => s.Name == name && s.EntityType == entityType && s.EntityId == entityId); + } + + public async Task> GetListAsync(string entityType, string entityId) + { + return await DbSet.Where(s => s.EntityType == entityType && s.EntityId == entityId).ToListAsync(); + } + } +} diff --git a/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/IAbpSettingsDbContext.cs b/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/IAbpSettingsDbContext.cs new file mode 100644 index 0000000000..1ef5e93867 --- /dev/null +++ b/src/Volo.Abp.Settings.EntityFrameworkCore/Volo/Abp/Settings/EntityFrameworkCore/IAbpSettingsDbContext.cs @@ -0,0 +1,10 @@ +using Microsoft.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace Volo.Abp.Settings.EntityFrameworkCore +{ + public interface IAbpSettingsDbContext : IEfCoreDbContext + { + DbSet Settings { get; set; } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Settings/Volo.Abp.Settings.csproj b/src/Volo.Abp.Settings/Volo.Abp.Settings.csproj new file mode 100644 index 0000000000..a26679d049 --- /dev/null +++ b/src/Volo.Abp.Settings/Volo.Abp.Settings.csproj @@ -0,0 +1,20 @@ + + + + + + netstandard2.0 + Volo.Abp.Settings + Volo.Abp.Settings + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/AbpSettingsModule.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/AbpSettingsModule.cs new file mode 100644 index 0000000000..0018d495a4 --- /dev/null +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/AbpSettingsModule.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Settings +{ + public class AbpSettingsModule : AbpModule + { + public override void ConfigureServices(IServiceCollection services) + { + services.AddAssemblyOf(); + } + } +} diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/CurrentTenantSettingContributor.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/CurrentTenantSettingContributor.cs new file mode 100644 index 0000000000..efe95a552b --- /dev/null +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/CurrentTenantSettingContributor.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.Settings +{ + public class CurrentTenantSettingContributor : ISettingContributor + { + private readonly ISettingStore _settingStore; + + public CurrentTenantSettingContributor(ISettingStore settingStore) + { + _settingStore = settingStore; + } + + public async Task GetOrNull(string name) + { + //Optimization: Get all Tenant-42 settings and cache it! + var tenantId = 42; //Get from current tenant + return await _settingStore.GetOrNullAsync(name, "Tenant", tenantId.ToString()); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/DefaultSettingContributor.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/DefaultSettingContributor.cs new file mode 100644 index 0000000000..ce141b7ebd --- /dev/null +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/DefaultSettingContributor.cs @@ -0,0 +1,20 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.Settings +{ + public class DefaultSettingContributor : ISettingContributor + { + private readonly ISettingStore _settingStore; + + public DefaultSettingContributor(ISettingStore settingStore) + { + _settingStore = settingStore; + } + + public async Task GetOrNull(string name) + { + //Optimization: Get all settings and cache it! + return await _settingStore.GetOrNullAsync(name, null, null); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingContributor.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingContributor.cs new file mode 100644 index 0000000000..27fea72ff8 --- /dev/null +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingContributor.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.Settings +{ + public interface ISettingContributor + { + Task GetOrNull(string name); + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingManager.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingManager.cs new file mode 100644 index 0000000000..b768648e9d --- /dev/null +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingManager.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Volo.Abp.Settings +{ + public interface ISettingManager + { + Task GetOrNullAsync(string name); + + Task GetOrNullAsync(string name, string entityType, string entityId, bool fallback = true); + + Task> GetAllAsync(); + + Task> GetAllAsync(string entityType, string entityId, bool fallback = true); + + Task SetAsync(string name, string value); + + Task SetAsync(string name, string value, string entityType, string entityId); + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingStore.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingStore.cs new file mode 100644 index 0000000000..1c4924b1e3 --- /dev/null +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingStore.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using JetBrains.Annotations; + +namespace Volo.Abp.Settings +{ + public interface ISettingStore + { + Task GetOrNullAsync([NotNull] string name, [CanBeNull] string entityType, [CanBeNull] string entityId); + + Task SetAsync([NotNull] string name, [NotNull] string value, [CanBeNull] string entityType, [CanBeNull] string entityId); + + Task> GetListAsync([CanBeNull] string entityType, [CanBeNull] string entityId); + } +} diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingManager.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingManager.cs new file mode 100644 index 0000000000..da9a9c7b83 --- /dev/null +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingManager.cs @@ -0,0 +1,49 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Volo.Abp.Settings +{ + public class SettingManager : ISettingManager + { + public Task GetOrNullAsync(string name) + { + return GetOrNullAsync(name, null, null); + } + + public Task GetOrNullAsync(string name, string entityType, string entityId, bool fallback = true) + { + var contributors = new List(); + + foreach (var contributor in contributors) + { + var value = contributor.GetOrNull(name); + if (value != null) + { + return value; + } + } + + return null; + } + + public Task> GetAllAsync() + { + throw new System.NotImplementedException(); + } + + public Task> GetAllAsync(string entityType, string entityId, bool fallback = true) + { + throw new System.NotImplementedException(); + } + + public Task SetAsync(string name, string value) + { + throw new System.NotImplementedException(); + } + + public Task SetAsync(string name, string value, string entityType, string entityId) + { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingValue.cs b/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingValue.cs new file mode 100644 index 0000000000..99b2de33f1 --- /dev/null +++ b/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingValue.cs @@ -0,0 +1,22 @@ +namespace Volo.Abp.Settings +{ + public class SettingValue : NameValue + { + /// + /// Creates a new . + /// + public SettingValue() + { + + } + + /// + /// Creates a new . + /// + public SettingValue(string name, string value) + { + Name = name; + Value = value; + } + } +} \ No newline at end of file