Browse Source
Merge pull request #1505 from abpframework/maliming/SharedContractResolver
Resolve #1503 Reuse Contract Resolver, improve performance.
pull/1529/head
Halil İbrahim Kalkan
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with
46 additions and
21 deletions
-
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingContractResolver.cs
-
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/JsonNetAuditSerializer.cs
-
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/ApiDescriptionFinder.cs
-
framework/src/Volo.Abp.Json/Volo/Abp/Json/Newtonsoft/NewtonsoftJsonSerializer.cs
-
framework/src/Volo.Abp.Localization/Volo/Abp/Localization/Json/JsonLocalizationDictionaryBuilder.cs
-
framework/test/Volo.Abp.AspNetCore.Tests/Volo/Abp/AspNetCore/AbpAspNetCoreTestBase.cs
|
|
|
@ -1,4 +1,4 @@ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Reflection; |
|
|
|
using Newtonsoft.Json; |
|
|
|
|
|
|
|
@ -16,12 +16,29 @@ namespace Volo.Abp.Auditing |
|
|
|
|
|
|
|
public string Serialize(object obj) |
|
|
|
{ |
|
|
|
var options = new JsonSerializerSettings |
|
|
|
return JsonConvert.SerializeObject(obj, GetSharedJsonSerializerSettings()); |
|
|
|
} |
|
|
|
|
|
|
|
private static readonly object SyncObj = new object(); |
|
|
|
private static JsonSerializerSettings _sharedJsonSerializerSettings; |
|
|
|
|
|
|
|
private JsonSerializerSettings GetSharedJsonSerializerSettings() |
|
|
|
{ |
|
|
|
if (_sharedJsonSerializerSettings == null) |
|
|
|
{ |
|
|
|
ContractResolver = new AuditingContractResolver(Options.IgnoredTypes) |
|
|
|
}; |
|
|
|
lock (SyncObj) |
|
|
|
{ |
|
|
|
if (_sharedJsonSerializerSettings == null) |
|
|
|
{ |
|
|
|
_sharedJsonSerializerSettings = new JsonSerializerSettings |
|
|
|
{ |
|
|
|
ContractResolver = new AuditingContractResolver(Options.IgnoredTypes) |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return JsonConvert.SerializeObject(obj, options); |
|
|
|
return _sharedJsonSerializerSettings; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -18,6 +18,11 @@ namespace Volo.Abp.Http.Client.DynamicProxying |
|
|
|
|
|
|
|
protected IApiDescriptionCache Cache { get; } |
|
|
|
|
|
|
|
private static readonly JsonSerializerSettings SharedJsonSerializerSettings = new JsonSerializerSettings |
|
|
|
{ |
|
|
|
ContractResolver = new CamelCasePropertyNamesContractResolver() |
|
|
|
}; |
|
|
|
|
|
|
|
public ApiDescriptionFinder( |
|
|
|
IApiDescriptionCache cache, |
|
|
|
IDynamicProxyHttpClientFactory httpClientFactory) |
|
|
|
@ -94,11 +99,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying |
|
|
|
|
|
|
|
var result = JsonConvert.DeserializeObject( |
|
|
|
content, |
|
|
|
typeof(ApplicationApiDescriptionModel), |
|
|
|
new JsonSerializerSettings |
|
|
|
{ |
|
|
|
ContractResolver = new CamelCasePropertyNamesContractResolver() |
|
|
|
}); |
|
|
|
typeof(ApplicationApiDescriptionModel), SharedJsonSerializerSettings); |
|
|
|
|
|
|
|
return (ApplicationApiDescriptionModel)result; |
|
|
|
} |
|
|
|
|
|
|
|
@ -9,6 +9,9 @@ namespace Volo.Abp.Json.Newtonsoft |
|
|
|
{ |
|
|
|
private readonly AbpJsonIsoDateTimeConverter _dateTimeConverter; |
|
|
|
|
|
|
|
private static readonly CamelCaseExceptDictionaryKeysResolver SharedCamelCaseExceptDictionaryKeysResolver = |
|
|
|
new CamelCaseExceptDictionaryKeysResolver(); |
|
|
|
|
|
|
|
public NewtonsoftJsonSerializer(AbpJsonIsoDateTimeConverter dateTimeConverter) |
|
|
|
{ |
|
|
|
_dateTimeConverter = dateTimeConverter; |
|
|
|
@ -37,7 +40,7 @@ namespace Volo.Abp.Json.Newtonsoft |
|
|
|
|
|
|
|
if (camelCase) |
|
|
|
{ |
|
|
|
settings.ContractResolver = new CamelCaseExceptDictionaryKeysResolver(); |
|
|
|
settings.ContractResolver = SharedCamelCaseExceptDictionaryKeysResolver; |
|
|
|
} |
|
|
|
|
|
|
|
if (indented) |
|
|
|
|
|
|
|
@ -1,4 +1,4 @@ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IO; |
|
|
|
using Microsoft.Extensions.Localization; |
|
|
|
@ -9,6 +9,11 @@ namespace Volo.Abp.Localization.Json |
|
|
|
{ |
|
|
|
public static class JsonLocalizationDictionaryBuilder |
|
|
|
{ |
|
|
|
private static readonly JsonSerializerSettings SharedJsonSerializerSettings = new JsonSerializerSettings |
|
|
|
{ |
|
|
|
ContractResolver = new CamelCasePropertyNamesContractResolver() |
|
|
|
}; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Builds an <see cref="JsonLocalizationDictionaryBuilder" /> from given file.
|
|
|
|
/// </summary>
|
|
|
|
@ -35,11 +40,7 @@ namespace Volo.Abp.Localization.Json |
|
|
|
try |
|
|
|
{ |
|
|
|
jsonFile = JsonConvert.DeserializeObject<JsonLocalizationFile>( |
|
|
|
jsonString, |
|
|
|
new JsonSerializerSettings |
|
|
|
{ |
|
|
|
ContractResolver = new CamelCasePropertyNamesContractResolver() |
|
|
|
}); |
|
|
|
jsonString, SharedJsonSerializerSettings); |
|
|
|
} |
|
|
|
catch (JsonException ex) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -11,13 +11,16 @@ namespace Volo.Abp.AspNetCore |
|
|
|
public abstract class AbpAspNetCoreTestBase<TStartup> : AbpAspNetCoreIntegratedTestBase<TStartup> |
|
|
|
where TStartup : class |
|
|
|
{ |
|
|
|
private static readonly JsonSerializerSettings SharedJsonSerializerSettings = |
|
|
|
new JsonSerializerSettings |
|
|
|
{ |
|
|
|
ContractResolver = new CamelCasePropertyNamesContractResolver() |
|
|
|
}; |
|
|
|
|
|
|
|
protected virtual async Task<T> GetResponseAsObjectAsync<T>(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) |
|
|
|
{ |
|
|
|
var strResponse = await GetResponseAsStringAsync(url, expectedStatusCode); |
|
|
|
return JsonConvert.DeserializeObject<T>(strResponse, new JsonSerializerSettings |
|
|
|
{ |
|
|
|
ContractResolver = new CamelCasePropertyNamesContractResolver() |
|
|
|
}); |
|
|
|
return JsonConvert.DeserializeObject<T>(strResponse, SharedJsonSerializerSettings); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task<string> GetResponseAsStringAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) |
|
|
|
|