diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/InstanceFactory.cs b/Src/Asp.Net/SqlSugar/Infrastructure/InstanceFactory.cs index dec7ceb7b..51293c370 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/InstanceFactory.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/InstanceFactory.cs @@ -91,28 +91,28 @@ namespace SqlSugar } #region 9-12 - public static ISugarQueryable GetQueryable(ConnectionConfig currentConnectionConfig) + public static ISugarQueryable GetQueryable(ConnectionConfig currentConnectionConfig) { string className = "Queryable"; className = GetClassName(currentConnectionConfig.DbType.ToString(), className); - ISugarQueryable result = CreateInstance>(className); + ISugarQueryable result = CreateInstance>(className); return result; } - public static ISugarQueryable GetQueryable(ConnectionConfig currentConnectionConfig) + public static ISugarQueryable GetQueryable(ConnectionConfig currentConnectionConfig) { string className = "Queryable"; className = GetClassName(currentConnectionConfig.DbType.ToString(), className); - ISugarQueryable result = CreateInstance>(className); + ISugarQueryable result = CreateInstance>(className); return result; } - public static ISugarQueryable GetQueryable(ConnectionConfig currentConnectionConfig) + public static ISugarQueryable GetQueryable(ConnectionConfig currentConnectionConfig) { string className = "Queryable"; className = GetClassName(currentConnectionConfig.DbType.ToString(), className); - ISugarQueryable result = CreateInstance>(className); + ISugarQueryable result = CreateInstance>(className); return result; } - public static ISugarQueryable GetQueryable(ConnectionConfig currentConnectionConfig) + public static ISugarQueryable GetQueryable(ConnectionConfig currentConnectionConfig) { string className = "Queryable"; className = GetClassName(currentConnectionConfig.DbType.ToString(), className); @@ -183,7 +183,8 @@ namespace SqlSugar { return new OracleUpdateable(); } - else { + else + { return new UpdateableProvider(); } } @@ -289,21 +290,21 @@ namespace SqlSugar } #region 9-12 - private static Restult CreateInstance(string className) + private static Restult CreateInstance(string className) { - return CreateInstance(className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8),typeof(T9)); + return CreateInstance(className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9)); } - private static Restult CreateInstance(string className) + private static Restult CreateInstance(string className) { - return CreateInstance(className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9),typeof(T10)); + return CreateInstance(className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10)); } - private static Restult CreateInstance(string className) + private static Restult CreateInstance(string className) { - return CreateInstance(className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10),typeof(T11)); + return CreateInstance(className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11)); } - private static Restult CreateInstance(string className) + private static Restult CreateInstance(string className) { - return CreateInstance(className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11),typeof(T12)); + return CreateInstance(className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12)); } #endregion @@ -353,5 +354,16 @@ namespace SqlSugar return result; } #endregion + + #region Services + public static ICacheManager GetCacheInstance() + { + return ReflectionInoCache.GetInstance(); + } + public static ISerializeManager GetSerializeInstance() + { + return SerializeManager.GetInstance(); + } + #endregion } } diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/RewritableMethods.cs b/Src/Asp.Net/SqlSugar/Infrastructure/RewritableMethods.cs index 690109171..7f9638f11 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/RewritableMethods.cs +++ b/Src/Asp.Net/SqlSugar/Infrastructure/RewritableMethods.cs @@ -191,7 +191,7 @@ namespace SqlSugar public string SerializeObject(object value) { DependencyManagement.TryJsonNet(); - return JsonHelper.SerializeObject(value); + return InstanceFactory.GetSerializeInstance().SerializeObject(value); } @@ -204,7 +204,7 @@ namespace SqlSugar public T DeserializeObject(string value) { DependencyManagement.TryJsonNet(); - return JsonHelper.DeserializeObject(value); + return InstanceFactory.GetSerializeInstance().DeserializeObject(value); } #endregion diff --git a/Src/Asp.Net/SqlSugar/Interface/ISerializeManager.cs b/Src/Asp.Net/SqlSugar/Interface/ISerializeManager.cs new file mode 100644 index 000000000..dc1dbed3e --- /dev/null +++ b/Src/Asp.Net/SqlSugar/Interface/ISerializeManager.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SqlSugar +{ + public interface ISerializeManager + { + string SerializeObject(object value); + T DeserializeObject(string value); + } +} diff --git a/Src/Asp.Net/SqlSugar/SqlSugar.csproj b/Src/Asp.Net/SqlSugar/SqlSugar.csproj index 7a958c136..79ace7575 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugar.csproj +++ b/Src/Asp.Net/SqlSugar/SqlSugar.csproj @@ -93,10 +93,11 @@ + - + diff --git a/Src/Asp.Net/SqlSugar/Utilities/JsonHelper.cs b/Src/Asp.Net/SqlSugar/Utilities/JsonHelper.cs deleted file mode 100644 index 5a2b45b4c..000000000 --- a/Src/Asp.Net/SqlSugar/Utilities/JsonHelper.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace SqlSugar -{ - internal class JsonHelper - { - public static string SerializeObject(object value) - { - return JsonConvert.SerializeObject(value); - } - - public static T DeserializeObject(string value) - { - var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - return JsonConvert.DeserializeObject(value, jSetting); - } - } -} diff --git a/Src/Asp.Net/SqlSugar/Utilities/SerializeManager.cs b/Src/Asp.Net/SqlSugar/Utilities/SerializeManager.cs new file mode 100644 index 000000000..60d9b73f2 --- /dev/null +++ b/Src/Asp.Net/SqlSugar/Utilities/SerializeManager.cs @@ -0,0 +1,33 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SqlSugar +{ + public class SerializeManager:ISerializeManager + { + private static SerializeManager _instance = null; + private static readonly object _instanceLock = new object(); + public static SerializeManager GetInstance() { + if (_instance == null) + lock (_instanceLock) + if (_instance == null) + { + _instance = new SerializeManager(); + } + return _instance; + } + public string SerializeObject(object value) + { + return JsonConvert.SerializeObject(value); + } + + public T DeserializeObject(string value) + { + var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + return JsonConvert.DeserializeObject(value, jSetting); + } + } +}