Files
StoreWeb/Store.KJDWebService/Services/ServiceBase.cs
T

41 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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(KJDConfig.GetConnection(connKey), isUseTrans);
}
/// <summary>读取配置(旧 ConfigurationManager.ConnectionStrings["key"].ConnectionString)</summary>
protected string Config(string key)
{
return KJDConfig.Get(key);
}
}
}