feat: 添加配置管理模块
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.EntityFrameworkCore;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
|
||||
namespace Volo.Abp.SettingManagement.EntityFrameworkCore;
|
||||
|
||||
[IgnoreMultiTenancy]
|
||||
[ConnectionStringName(AbpSettingManagementDbProperties.ConnectionStringName)]
|
||||
public interface ISettingManagementDbContext : IEfCoreDbContext
|
||||
{
|
||||
DbSet<Setting> Settings { get; }
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.EntityFrameworkCore;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
|
||||
namespace Volo.Abp.SettingManagement.EntityFrameworkCore;
|
||||
|
||||
[IgnoreMultiTenancy]
|
||||
[ConnectionStringName(AbpSettingManagementDbProperties.ConnectionStringName)]
|
||||
public class SettingManagementDbContext : AbpDbContext<SettingManagementDbContext>, ISettingManagementDbContext
|
||||
{
|
||||
public DbSet<Setting> Settings { get; set; }
|
||||
|
||||
public SettingManagementDbContext(DbContextOptions<SettingManagementDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.ConfigureSettingManagement();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Volo.Abp.EntityFrameworkCore.Modeling;
|
||||
|
||||
namespace Volo.Abp.SettingManagement.EntityFrameworkCore;
|
||||
|
||||
public static class SettingManagementDbContextModelBuilderExtensions
|
||||
{
|
||||
//TODO: Instead of getting parameters, get a action of SettingManagementModelBuilderConfigurationOptions like other modules
|
||||
public static void ConfigureSettingManagement(
|
||||
[NotNull] this ModelBuilder builder)
|
||||
{
|
||||
Check.NotNull(builder, nameof(builder));
|
||||
|
||||
if (builder.IsTenantOnlyDatabase())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
builder.Entity<Setting>(b =>
|
||||
{
|
||||
b.ToTable(AbpSettingManagementDbProperties.DbTablePrefix + "Settings", AbpSettingManagementDbProperties.DbSchema);
|
||||
|
||||
b.ConfigureByConvention();
|
||||
|
||||
b.Property(x => x.Name).HasMaxLength(SettingConsts.MaxNameLength).IsRequired();
|
||||
|
||||
if (builder.IsUsingOracle()) { SettingConsts.MaxValueLengthValue = 2000; }
|
||||
b.Property(x => x.Value).HasMaxLength(SettingConsts.MaxValueLengthValue).IsRequired();
|
||||
|
||||
b.Property(x => x.ProviderName).HasMaxLength(SettingConsts.MaxProviderNameLength);
|
||||
b.Property(x => x.ProviderKey).HasMaxLength(SettingConsts.MaxProviderKeyLength);
|
||||
|
||||
b.HasIndex(x => new { x.Name, x.ProviderName, x.ProviderKey }).IsUnique(true);
|
||||
|
||||
b.ApplyObjectExtensionMappings();
|
||||
});
|
||||
|
||||
builder.TryConfigureObjectExtensions<SettingManagementDbContext>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Yi.Framework.SettingManagement.Domain;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
using Yi.Framework.SqlSugarCore.Repositories;
|
||||
|
||||
namespace Volo.Abp.SettingManagement.EntityFrameworkCore;
|
||||
|
||||
public class SqlSugarCoreSettingRepository : SqlSugarRepository<SettingEntity, Guid>,
|
||||
ISettingRepository
|
||||
{
|
||||
public SqlSugarCoreSettingRepository(ISugarDbContextProvider<ISqlSugarDbContext> sugarDbContextProvider) : base(sugarDbContextProvider)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual async Task<SettingEntity> FindAsync(
|
||||
string name,
|
||||
string providerName,
|
||||
string providerKey,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _DbQueryable
|
||||
.Where(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey)
|
||||
.OrderBy(x => x.Id)
|
||||
.FirstAsync();
|
||||
}
|
||||
|
||||
public virtual async Task<List<SettingEntity>> GetListAsync(
|
||||
string providerName,
|
||||
string providerKey,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _DbQueryable
|
||||
.Where(
|
||||
s => s.ProviderName == providerName && s.ProviderKey == providerKey
|
||||
).ToListAsync();
|
||||
}
|
||||
|
||||
public virtual async Task<List<SettingEntity>> GetListAsync(
|
||||
string[] names,
|
||||
string providerName,
|
||||
string providerKey,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _DbQueryable
|
||||
.Where(
|
||||
s => names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey
|
||||
).ToListAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\framework\Yi.Framework.SqlSugarCore\Yi.Framework.SqlSugarCore.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.SettingManagement.Domain\Yi.Framework.SettingManagement.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,21 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.SettingManagement.EntityFrameworkCore;
|
||||
using Yi.Framework.SettingManagement.Domain;
|
||||
using Yi.Framework.SqlSugarCore;
|
||||
|
||||
namespace Yi.Framework.SettingManagement.SqlSugarCore
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(YiFrameworkSettingManagementDomainModule),
|
||||
typeof(YiFrameworkSqlSugarCoreModule)
|
||||
)]
|
||||
public class YiFrameworkSettingManagementSqlSugarCoreModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
var services = context.Services;
|
||||
services.AddTransient<ISettingRepository, SqlSugarCoreSettingRepository>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user