惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
博客园 - 叶小钗
The GitHub Blog
The GitHub Blog
Microsoft Azure Blog
Microsoft Azure Blog
N
News and Events Feed by Topic
Cloudbric
Cloudbric
B
Blog
Cisco Talos Blog
Cisco Talos Blog
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic
V
Visual Studio Blog
A
Arctic Wolf
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42
S
Security @ Cisco Blogs
博客园 - 聂微东
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
G
GRAHAM CLULEY
L
LINUX DO - 热门话题
量子位
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tenable Blog
月光博客
月光博客
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
D
Docker
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Help Net Security
Help Net Security
D
DataBreaches.Net

博客园 - Hey,Coder!

Elasticsearch ILM 与 Data Stream 概念及实例说明文档 portainer httphelper封装 Ocelot + Consul + SignalR 粘性会话 正交软件架构 docker postgresql17 主从复制 rabbitmq总结与c#示例 docker rabbitmq quartz dashboard docker consul registrator 服务自动注册consul 微服务动态扩容 ubuntu24.04 安装docker RAG 检索增强生成 软考 - 架构设计师 知识点总结 c# MailKit3.4.3 发送邮件、附件 nginx 反向代理postgresql c# 信号量 elsa 3.5 中间件记录最后执行的节点数据 xp密钥 c# System.Text.Json 反序列化Dictionary<string,object>时未转换基础类型的处理方法 docker配置代理 openclaw 接入 LMStudio的模型服务 wpf canvas 移动 缩放 windows平台openclaw搭建 wpf scrollerview触摸滚动 c# Elastic.Clients.Elasticsearch 动态查询 c# es 封装Elastic.Clients.Elasticsearch c# scrollerview滚动到指定元素位置 WPF 重写Expander 基于elsa工作流封装一套变量、组件的体系 常用活动重写 DynamicExpresso 轻量级动态表达式库 c# elsa 3.5.2 程序化工作流常用功能及自定义中间件 leaflet docker 连接老版本的sqlserver ssl错误 c# quartz 动态创建任务 控制任务运行和停止 依赖注入 cefsharp 模拟点击 批量重置数据库的数据 docker 复制远程镜像本地并创建容器 c# newtonsoft dynamic
c# 动态切换sqlsugar连接字符串
Hey,Coder! · 2026-03-06 · via 博客园 - Hey,Coder!
 public class BLLDBService
 {
     private static ConcurrentDictionary<string, ISqlSugarClient> DBList = new();

     private readonly ISqlSugarClient sqlSugar;

     private readonly IServiceProvider serviceProvider;
     public BLLDBService(ISqlSugarClient sqlSugar, IServiceProvider serviceProvider)
     {
         this.sqlSugar = sqlSugar;
         this.serviceProvider = serviceProvider;
     }



     private ISqlSugarClient GetDBClient(string dbNo)
     {

         if (!DBList.ContainsKey(dbNo))
         {
             throw new Exception("DBCannotCreate");
         }

            return DBList[dbNo];
     }

     public static void InjectDB(string dbNo, SqlSugar.DbType dbType, string connectionStr)
     {
         DBList.AddOrUpdate(dbNo, f =>
               new SqlSugarScope(new ConnectionConfig()
            {
                DbType = dbType,
                ConnectionString = connectionStr,
                IsAutoCloseConnection = true,
                AopEvents = new AopEvents
                {
                    OnLogExecuting = (log, para) =>
                    {
                        //Console.WriteLine(log);
                    }
                }
            })
         , (f, client) =>
               new SqlSugarScope(new ConnectionConfig()
            {
                DbType = dbType,
                ConnectionString = connectionStr,
                IsAutoCloseConnection = true,
                AopEvents = new AopEvents
                {
                    OnLogExecuting = (log, para) =>
                    {
                        //Console.WriteLine(log);
                    }
                }
            })
        );
     }

     public static void DetectAndInjectDB(string dbNo, SqlSugar.DbType dbType, string connectionStr)
     {
         if (!DBList.ContainsKey(dbNo))
         {
             InjectDB( dbNo, dbType,  connectionStr);
             return;
         }

         var oldData = DBList[dbNo];

         if (oldData?.CurrentConnectionConfig == null)
         {
             InjectDB(dbNo, dbType, connectionStr);
             return;
         }

         if (oldData.CurrentConnectionConfig.ConnectionString != connectionStr||
             oldData.CurrentConnectionConfig.DbType != dbType)
         {
             InjectDB(dbNo, dbType, connectionStr);
             return;
         }
     }
 }