41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using FreeSql;
|
||
using MAX.Core.DependencyInjection;
|
||
using Microsoft.Extensions.Configuration;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using StoreHub.Framework.Repositorys;
|
||
using StoreHub.KJDWebService.Commons;
|
||
|
||
namespace StoreHub.KJDWebService.Services
|
||
{
|
||
/// <summary>
|
||
/// 迁移服务基类:注入 SqlRepository(提供 KJDDB IAdo)与 IConfiguration。
|
||
/// 提供 MySql(connKey[, isUseTrans]) 创建与旧 MysqlUtils 兼容的执行器(内部参数化执行)。
|
||
/// </summary>
|
||
public abstract class ServiceBase : ITransientDependency
|
||
{
|
||
protected readonly SqlRepository _sqlRepository;
|
||
protected readonly IConfiguration _configuration;
|
||
|
||
protected ServiceBase(SqlRepository sqlRepository, IConfiguration configuration)
|
||
{
|
||
_sqlRepository = sqlRepository;
|
||
_configuration = configuration;
|
||
}
|
||
|
||
/// <summary>KJDDB 的 IAdo(等效旧 ConnKJD)</summary>
|
||
protected IAdo Ado => _sqlRepository.Ado;
|
||
|
||
/// <summary>创建 MysqlUtils(等效旧 new MysqlUtils(conn[, isUseTrans]))</summary>
|
||
protected MysqlUtils MySql(string connKey, bool isUseTrans = false)
|
||
{
|
||
return new MysqlUtils(AdoProvider.Get(connKey), isUseTrans);
|
||
}
|
||
|
||
/// <summary>读取配置(旧 ConfigurationManager.ConnectionStrings["key"].ConnectionString)</summary>
|
||
protected string Config(string key)
|
||
{
|
||
return KJDConfig.Get(key);
|
||
}
|
||
}
|
||
}
|