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
{
///
/// 迁移服务基类:注入 SqlRepository(提供 KJDDB IAdo)与 IConfiguration。
/// 提供 MySql(connKey[, isUseTrans]) 创建与旧 MysqlUtils 兼容的执行器(内部参数化执行)。
///
public abstract class ServiceBase : ITransientDependency
{
protected readonly SqlRepository _sqlRepository;
protected readonly IConfiguration _configuration;
protected ServiceBase(SqlRepository sqlRepository, IConfiguration configuration)
{
_sqlRepository = sqlRepository;
_configuration = configuration;
}
/// KJDDB 的 IAdo(等效旧 ConnKJD)
protected IAdo Ado => _sqlRepository.Ado;
/// 创建 MysqlUtils(等效旧 new MysqlUtils(conn[, isUseTrans]))
protected MysqlUtils MySql(string connKey, bool isUseTrans = false)
{
return new MysqlUtils(AdoProvider.Get(connKey), isUseTrans);
}
/// 读取配置(旧 ConfigurationManager.ConnectionStrings["key"].ConnectionString)
protected string Config(string key)
{
return KJDConfig.Get(key);
}
}
}