mirror of https://github.com/abpframework/abp.git
25 changed files with 463 additions and 3 deletions
@ -0,0 +1,22 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.Settings.Domain</AssemblyName> |
||||
|
<PackageId>Volo.Abp.Settings.Domain</PackageId> |
||||
|
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Volo.Abp.Ddd\Volo.Abp.Ddd.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.MultiTenancy.Abstractions\Volo.Abp.MultiTenancy.Abstractions.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.Settings\Volo.Abp.Settings.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -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<AbpSettingsDomainModule>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<Setting, Guid> |
||||
|
{ |
||||
|
Task<Setting> FindAsync(string name, string entityType, string entityId); |
||||
|
|
||||
|
Task<List<Setting>> GetListAsync(string entityType, string entityId); |
||||
|
} |
||||
|
} |
||||
@ -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<Guid>, 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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<string> 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<List<SettingValue>> GetListAsync(string entityType, string entityId) |
||||
|
{ |
||||
|
var setting = await _settingRepository.GetListAsync(entityType, entityId); |
||||
|
return setting.Select(s => new SettingValue(s.Name, s.Value)).ToList(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.Settings.EntityFrameworkCore</AssemblyName> |
||||
|
<PackageId>Volo.Abp.Settings.EntityFrameworkCore</PackageId> |
||||
|
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Volo.Abp.EntityFrameworkCore\Volo.Abp.EntityFrameworkCore.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.Settings.Domain\Volo.Abp.Settings.Domain.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,16 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Abp.Settings.EntityFrameworkCore |
||||
|
{ |
||||
|
public class AbpSettingsDbContext : AbpDbContext<AbpSettingsDbContext>, IAbpSettingsDbContext |
||||
|
{ |
||||
|
public DbSet<Setting> Settings { get; set; } |
||||
|
|
||||
|
public AbpSettingsDbContext(DbContextOptions<AbpSettingsDbContext> options) |
||||
|
: base(options) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<AbpSettingsDbContext>(options => |
||||
|
{ |
||||
|
options.AddDefaultRepositories<IAbpSettingsDbContext>(); |
||||
|
|
||||
|
options.AddRepository<Setting, EfCoreSettingRepository>(); |
||||
|
}); |
||||
|
|
||||
|
services.AddAssemblyOf<AbpSettingsEntityFrameworkCoreModule>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<IAbpSettingsDbContext, Setting, Guid>, ISettingRepository |
||||
|
{ |
||||
|
public EfCoreSettingRepository(IDbContextProvider<IAbpSettingsDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<Setting> FindAsync(string name, string entityType, string entityId) |
||||
|
{ |
||||
|
return await DbSet.FirstOrDefaultAsync(s => s.Name == name && s.EntityType == entityType && s.EntityId == entityId); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<Setting>> GetListAsync(string entityType, string entityId) |
||||
|
{ |
||||
|
return await DbSet.Where(s => s.EntityType == entityType && s.EntityId == entityId).ToListAsync(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Abp.Settings.EntityFrameworkCore |
||||
|
{ |
||||
|
public interface IAbpSettingsDbContext : IEfCoreDbContext |
||||
|
{ |
||||
|
DbSet<Setting> Settings { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.Settings</AssemblyName> |
||||
|
<PackageId>Volo.Abp.Settings</PackageId> |
||||
|
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -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<AbpSettingsModule>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<string> 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()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<string> GetOrNull(string name) |
||||
|
{ |
||||
|
//Optimization: Get all settings and cache it!
|
||||
|
return await _settingStore.GetOrNullAsync(name, null, null); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.Settings |
||||
|
{ |
||||
|
public interface ISettingContributor |
||||
|
{ |
||||
|
Task<string> GetOrNull(string name); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.Settings |
||||
|
{ |
||||
|
public interface ISettingManager |
||||
|
{ |
||||
|
Task<string> GetOrNullAsync(string name); |
||||
|
|
||||
|
Task<string> GetOrNullAsync(string name, string entityType, string entityId, bool fallback = true); |
||||
|
|
||||
|
Task<List<SettingValue>> GetAllAsync(); |
||||
|
|
||||
|
Task<List<SettingValue>> GetAllAsync(string entityType, string entityId, bool fallback = true); |
||||
|
|
||||
|
Task SetAsync(string name, string value); |
||||
|
|
||||
|
Task SetAsync(string name, string value, string entityType, string entityId); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.Settings |
||||
|
{ |
||||
|
public interface ISettingStore |
||||
|
{ |
||||
|
Task<string> 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<List<SettingValue>> GetListAsync([CanBeNull] string entityType, [CanBeNull] string entityId); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,49 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.Settings |
||||
|
{ |
||||
|
public class SettingManager : ISettingManager |
||||
|
{ |
||||
|
public Task<string> GetOrNullAsync(string name) |
||||
|
{ |
||||
|
return GetOrNullAsync(name, null, null); |
||||
|
} |
||||
|
|
||||
|
public Task<string> GetOrNullAsync(string name, string entityType, string entityId, bool fallback = true) |
||||
|
{ |
||||
|
var contributors = new List<ISettingContributor>(); |
||||
|
|
||||
|
foreach (var contributor in contributors) |
||||
|
{ |
||||
|
var value = contributor.GetOrNull(name); |
||||
|
if (value != null) |
||||
|
{ |
||||
|
return value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
public Task<List<SettingValue>> GetAllAsync() |
||||
|
{ |
||||
|
throw new System.NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public Task<List<SettingValue>> 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(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
namespace Volo.Abp.Settings |
||||
|
{ |
||||
|
public class SettingValue : NameValue |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Creates a new <see cref="NameValue"/>.
|
||||
|
/// </summary>
|
||||
|
public SettingValue() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Creates a new <see cref="NameValue"/>.
|
||||
|
/// </summary>
|
||||
|
public SettingValue(string name, string value) |
||||
|
{ |
||||
|
Name = name; |
||||
|
Value = value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue