ow
This commit is contained in:
commit
f05d2d215f
678 files changed
+73865
No files matched your search
@@ -0,0 +1,50 @@
|
||||
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
||||
|
||||
namespace CloudBuilder.Core.Application.Options
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据上下文配置节点
|
||||
/// </summary>
|
||||
public class CloudBuilderDbContextOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化一个<see cref="CloudBuilderDbContextOptions"/>类型的新实例
|
||||
/// </summary>
|
||||
public CloudBuilderDbContextOptions()
|
||||
{
|
||||
LazyLoadingProxiesEnabled = false;
|
||||
AuditEntityEnabled = false;
|
||||
AutoMigrationEnabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 上下文类型全名
|
||||
/// </summary>
|
||||
public string DbContextTypeName { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 连接字符串
|
||||
/// </summary>
|
||||
public string ConnectionString { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 数据库类型
|
||||
/// </summary>
|
||||
public DatabaseType DatabaseType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 是否启用延迟加载代理
|
||||
/// </summary>
|
||||
public bool LazyLoadingProxiesEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 是否允许审计实体
|
||||
/// </summary>
|
||||
public bool AuditEntityEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 是否自动迁移
|
||||
/// </summary>
|
||||
public bool AutoMigrationEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Core.Application.Options
|
||||
{
|
||||
/// <summary>
|
||||
/// CloudBuilder框架配置选项信息
|
||||
/// </summary>
|
||||
public class CloudBuilderOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化一个<see cref="CloudBuilderOptions"/>类型的新实例
|
||||
/// </summary>
|
||||
public CloudBuilderOptions()
|
||||
{
|
||||
DbContexts = new ConcurrentDictionary<string, CloudBuilderDbContextOptions>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 数据上下文配置信息
|
||||
/// </summary>
|
||||
public IDictionary<string, CloudBuilderDbContextOptions> DbContexts { get; }
|
||||
|
||||
///// <summary>
|
||||
///// 获取 第三方OAuth2登录配置信息
|
||||
///// </summary>
|
||||
//public IDictionary<string, OAuth2Options> OAuth2S { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 邮件发送选项
|
||||
/// </summary>
|
||||
public MailSenderOptions MailSender { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 全局授权
|
||||
/// </summary>
|
||||
public bool EnableGlobalAuthorize { get; set; }
|
||||
/// <summary>
|
||||
/// 获取或设置 JWT身份认证选项
|
||||
/// </summary>
|
||||
public JwtOptions Jwt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 Redis选项
|
||||
/// </summary>
|
||||
public RedisOptions Redis { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 获取或设置 Swagger选项
|
||||
///// </summary>
|
||||
//public SwaggerOptions Swagger { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 获取或设置 Http传输加密选项
|
||||
///// </summary>
|
||||
//public HttpEncryptOptions HttpEncrypt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定上下文类和指定数据库类型的上下文配置信息
|
||||
/// </summary>
|
||||
public CloudBuilderDbContextOptions GetDbContextOptions(string dbContextType)
|
||||
{
|
||||
return DbContexts.Values.SingleOrDefault(m => m.DbContextTypeName == dbContextType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using CloudBuilder.Core.Extensions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace CloudBuilder.Core.Application.Options
|
||||
{
|
||||
/// <summary>
|
||||
/// CloudBuilder配置选项创建器
|
||||
/// </summary>
|
||||
public class CloudBuilderOptionsSetup : IConfigureOptions<CloudBuilderOptions>
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化一个<see cref="CloudBuilderOptionsSetup"/>类型的新实例
|
||||
/// </summary>
|
||||
public CloudBuilderOptionsSetup(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
/// <summary>Invoked to configure a TOptions instance.</summary>
|
||||
/// <param name="options">The options instance to configure.</param>
|
||||
public void Configure(CloudBuilderOptions options)
|
||||
{
|
||||
SetDbContextOptions(options);
|
||||
|
||||
IConfigurationSection section;
|
||||
|
||||
//MailSender
|
||||
section = _configuration.GetSection("CloudBuilder:MailSender");
|
||||
MailSenderOptions sender = section.Get<MailSenderOptions>();
|
||||
if (sender != null)
|
||||
{
|
||||
if (sender.Password == null)
|
||||
{
|
||||
sender.Password = _configuration["CloudBuilder:MailSender:Password"];
|
||||
}
|
||||
options.MailSender = sender;
|
||||
}
|
||||
|
||||
//EnableGlobalAuthorize
|
||||
section = _configuration.GetSection("CloudBuilder:Authorization:EnableGlobalAuthorize");
|
||||
options.EnableGlobalAuthorize = section.Get<bool>();
|
||||
|
||||
//JwtOptions
|
||||
section = _configuration.GetSection("CloudBuilder:Jwt");
|
||||
JwtOptions jwt = section.Get<JwtOptions>();
|
||||
if (jwt != null)
|
||||
{
|
||||
if (jwt.Secret == null)
|
||||
{
|
||||
jwt.Secret = _configuration["CloudBuilder:Jwt:Secret"];
|
||||
}
|
||||
options.Jwt = jwt;
|
||||
}
|
||||
|
||||
// RedisOptions
|
||||
section = _configuration.GetSection("CloudBuilder:Redis");
|
||||
RedisOptions redis = section.Get<RedisOptions>();
|
||||
if (redis != null)
|
||||
{
|
||||
if (redis.Configuration.IsMissing())
|
||||
{
|
||||
throw new Exception("配置文件中Redis节点的Configuration不能为空");
|
||||
}
|
||||
options.Redis = redis;
|
||||
}
|
||||
|
||||
//// SwaggerOptions
|
||||
//section = _configuration.GetSection("CloudBuilder:Swagger");
|
||||
//SwaggerOptions swagger = section.Get<SwaggerOptions>();
|
||||
//if (swagger != null)
|
||||
//{
|
||||
// if (swagger.Url.IsMissing())
|
||||
// {
|
||||
// throw new CloudBuilderException("配置文件中Swagger节点的Url不能为空");
|
||||
// }
|
||||
// options.Swagger = swagger;
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化上下文配置信息,首先以CloudBuilder配置节点中的为准,
|
||||
/// 不存在CloudBuilder节点,才使用ConnectionStrings的数据连接串来构造SqlServer的配置,
|
||||
/// 保证同一上下文类型只有一个配置节点
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
private void SetDbContextOptions(CloudBuilderOptions options)
|
||||
{
|
||||
IConfigurationSection section = _configuration.GetSection("CloudBuilder:DbContexts");
|
||||
IDictionary<string, CloudBuilderDbContextOptions> dict = section.Get<Dictionary<string, CloudBuilderDbContextOptions>>();
|
||||
|
||||
var repeated = dict.Values.GroupBy(m => m.DbContextTypeName).FirstOrDefault(m => m.Count() > 1);
|
||||
if (repeated != null)
|
||||
{
|
||||
throw new Exception($"数据上下文配置中存在多个配置节点指向同一个上下文类型:{repeated.First().DbContextTypeName}");
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<string, CloudBuilderDbContextOptions> pair in dict)
|
||||
{
|
||||
options.DbContexts.Add(pair.Key, pair.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Core.Application.Options
|
||||
{
|
||||
/// <summary>
|
||||
/// JWT身份认证选项
|
||||
/// </summary>
|
||||
public class JwtOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置 密钥
|
||||
/// </summary>
|
||||
public string Secret { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 发行方
|
||||
/// </summary>
|
||||
public string Issuer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 订阅方
|
||||
/// </summary>
|
||||
public string Audience { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 AccessToken有效期分钟数
|
||||
/// </summary>
|
||||
public double AccessExpireMins { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 RefreshToken有效期分钟数
|
||||
/// </summary>
|
||||
public double RefreshExpireMins { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 RefreshToken是否绝对过期
|
||||
/// </summary>
|
||||
public bool IsRefreshAbsoluteExpired { get; set; } = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Core.Application.Options
|
||||
{
|
||||
/// <summary>
|
||||
/// 邮件发送选项
|
||||
/// </summary>
|
||||
public class MailSenderOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置 邮件发送服务器
|
||||
/// </summary>
|
||||
public string Host { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 端口
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 是否SSL
|
||||
/// </summary>
|
||||
public bool EnableSsl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 发送方显示名
|
||||
/// </summary>
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 发送方用户名
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 发送方密码
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Core.Application.Options
|
||||
{
|
||||
/// <summary>
|
||||
/// Redis选项
|
||||
/// </summary>
|
||||
public class RedisOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置 Redis连接配置
|
||||
/// </summary>
|
||||
public string Configuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置 Redis实例名称
|
||||
/// </summary>
|
||||
public string InstanceName { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user