ConnectionConfig.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace SqlSugar
  10. {
  11. public class ConnectionConfig
  12. {
  13. /// <summary>
  14. ///Connection unique code
  15. /// </summary>
  16. public object ConfigId { get; set; }
  17. /// <summary>
  18. ///DbType.SqlServer Or Other
  19. /// </summary>
  20. public DbType DbType { get; set; }
  21. /// <summary>
  22. ///Database Connection string
  23. /// </summary>
  24. public string ConnectionString { get; set; }
  25. /// <summary>
  26. /// QueryableWithAttr queries go to DbLinkName, which is commonly used for cross-library queries
  27. /// </summary>
  28. public string DbLinkName { get; set; }
  29. /// <summary>
  30. /// true does not need to close the connection
  31. /// </summary>
  32. public bool IsAutoCloseConnection { get; set; }
  33. /// <summary>
  34. /// Default Attribute
  35. /// </summary>
  36. public InitKeyType InitKeyType = InitKeyType.Attribute;
  37. /// <summary>
  38. /// Exception prompt language
  39. /// </summary>
  40. public LanguageType LanguageType { get=>ErrorMessage.SugarLanguageType; set=>ErrorMessage.SugarLanguageType=value; }
  41. /// <summary>
  42. ///If true, there is only one connection instance in the same thread within the same connection string
  43. //[Obsolete("use SqlSugar.Ioc")]
  44. ///// </summary>
  45. //public bool IsShardSameThread { get; set; }
  46. /// <summary>
  47. /// Configure External Services replace default services,For example, Redis storage
  48. /// </summary>
  49. [JsonIgnore]
  50. public ConfigureExternalServices ConfigureExternalServices = new ConfigureExternalServices();
  51. /// <summary>
  52. /// If SlaveConnectionStrings has value,ConnectionString is write operation, SlaveConnectionStrings is read operation.
  53. /// All operations within a transaction is ConnectionString
  54. /// </summary>
  55. public List<SlaveConnectionConfig> SlaveConnectionConfigs { get; set; }
  56. /// <summary>
  57. /// More Gobal Settings
  58. /// </summary>
  59. public ConnMoreSettings MoreSettings { get; set; }
  60. ///// <summary>
  61. ///// Used for debugging errors or BUG,Used for debugging, which has an impact on Performance
  62. ///// </summary>
  63. //public SugarDebugger Debugger { get; set; }
  64. public string IndexSuffix { get; set; }
  65. [JsonIgnore]
  66. public AopEvents AopEvents { get;set; }
  67. /// <summary>
  68. ///
  69. /// </summary>
  70. public SqlMiddle SqlMiddle { get; set; }
  71. }
  72. public class SqlMiddle
  73. {
  74. public bool? IsSqlMiddle { get; set; }
  75. public Func<string, SugarParameter[], object> GetScalar { get; set; } = (s,p) => throw new Exception("SqlMiddle.GetScalar is null");
  76. public Func<string, SugarParameter[],int> ExecuteCommand { get; set; } = (s, p) => throw new Exception("SqlMiddle.ExecuteCommand is null");
  77. public Func<string, SugarParameter[],IDataReader> GetDataReader { get; set; } = (s, p) => throw new Exception("SqlMiddle.GetDataReader is null");
  78. public Func<string, SugarParameter[],DataSet> GetDataSetAll { get; set; } = (s, p) => throw new Exception("SqlMiddle.GetDataSetAll is null");
  79. public Func<string, SugarParameter[], Task<object>> GetScalarAsync { get; set; } = (s, p) => throw new Exception("SqlMiddle.GetScalarAsync is null");
  80. public Func<string, SugarParameter[], Task<int>> ExecuteCommandAsync { get; set; } = (s, p) => throw new Exception("SqlMiddle.ExecuteCommandAsync is null");
  81. public Func<string, SugarParameter[], Task<IDataReader>> GetDataReaderAsync { get; set; } = (s, p) => throw new Exception("SqlMiddle.GetDataReaderAsync is null");
  82. public Func<string, SugarParameter[], Task<DataSet>> GetDataSetAllAsync { get; set; } = (s, p) => throw new Exception("SqlMiddle.GetDataSetAllAsync is null");
  83. }
  84. public class AopEvents
  85. {
  86. public Action<DiffLogModel> OnDiffLogEvent { get; set; }
  87. public Action<SqlSugarException> OnError { get; set; }
  88. public Action<string, SugarParameter[]> OnLogExecuting { get; set; }
  89. public Action<string, SugarParameter[]> OnLogExecuted { get; set; }
  90. public Func<string, SugarParameter[], KeyValuePair<string, SugarParameter[]>> OnExecutingChangeSql { get; set; }
  91. public Action<object, DataFilterModel> DataExecuting { get; set; }
  92. public Action<object, DataAfterModel> DataExecuted { get; set; }
  93. }
  94. public class ConfigureExternalServices
  95. {
  96. private ISerializeService _SerializeService;
  97. private ICacheService _ReflectionInoCache;
  98. private ICacheService _DataInfoCache;
  99. private IRazorService _RazorService;
  100. public ISplitTableService SplitTableService { get; set; }
  101. public IRazorService RazorService
  102. {
  103. get
  104. {
  105. if (_RazorService == null)
  106. return _RazorService;
  107. else
  108. return _RazorService;
  109. }
  110. set { _RazorService = value; }
  111. }
  112. public ISerializeService SerializeService
  113. {
  114. get
  115. {
  116. if (_SerializeService == null)
  117. return DefaultServices.Serialize;
  118. else
  119. return _SerializeService;
  120. }
  121. set{ _SerializeService = value;}
  122. }
  123. public ICacheService ReflectionInoCacheService
  124. {
  125. get
  126. {
  127. if (_ReflectionInoCache == null)
  128. return DefaultServices.ReflectionInoCache;
  129. else
  130. return _ReflectionInoCache;
  131. }
  132. set{_ReflectionInoCache = value;}
  133. }
  134. public ICacheService DataInfoCacheService
  135. {
  136. get
  137. {
  138. if (_DataInfoCache == null)
  139. return DefaultServices.DataInoCache;
  140. else
  141. return _DataInfoCache;
  142. }
  143. set { _DataInfoCache = value; }
  144. }
  145. public List<SqlFuncExternal> SqlFuncServices { get; set; }
  146. public List<KeyValuePair<string, CSharpDataType>> AppendDataReaderTypeMappings { get; set; }
  147. public Action<PropertyInfo, EntityColumnInfo> EntityService{ get; set; }
  148. public Action<Type,EntityInfo> EntityNameService { get; set; }
  149. }
  150. }