-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from dotnetcore/dev
v1.1.0
- Loading branch information
Showing
48 changed files
with
1,387 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<EasyCachingCorePackageVersion>0.9.0</EasyCachingCorePackageVersion> | ||
<EasyCachingMemcachedPackageVersion>0.9.0</EasyCachingMemcachedPackageVersion> | ||
<EasyCachingRedisPackageVersion>0.9.0</EasyCachingRedisPackageVersion> | ||
<EasyCachingSQLitePackageVersion>0.9.0</EasyCachingSQLitePackageVersion> | ||
<EasyCachingInMemoryPackageVersion>0.9.0</EasyCachingInMemoryPackageVersion> | ||
<EasyCachingHybridPackageVersion>0.9.0</EasyCachingHybridPackageVersion> | ||
<EasyCachingAspectCorePackageVersion>0.9.0</EasyCachingAspectCorePackageVersion> | ||
<EasyCachingCastlePackageVersion>0.9.0</EasyCachingCastlePackageVersion> | ||
<EasyCachingResponseCachingPackageVersion>0.9.0</EasyCachingResponseCachingPackageVersion> | ||
<EasyCachingJsonPackageVersion>0.9.0</EasyCachingJsonPackageVersion> | ||
<EasyCachingMessagePackPackageVersion>0.9.0</EasyCachingMessagePackPackageVersion> | ||
<EasyCachingProtobufPackageVersion>0.9.0</EasyCachingProtobufPackageVersion> | ||
<EasyCachingCSRedisPackageVersion>0.9.0</EasyCachingCSRedisPackageVersion> | ||
<EasyCachingRedisBusPackageVersion>0.9.0</EasyCachingRedisBusPackageVersion> | ||
<EasyCachingCSRedisBusPackageVersion>0.9.0</EasyCachingCSRedisBusPackageVersion> | ||
<EasyCachingRabbitBusPackageVersion>0.9.0</EasyCachingRabbitBusPackageVersion> | ||
<EasyCachingDiskPackageVersion>0.9.0</EasyCachingDiskPackageVersion> | ||
<EasyCachingMsExtPackageVersion>0.9.0</EasyCachingMsExtPackageVersion> | ||
<EasyCachingLiteDBPackageVersion>0.9.0</EasyCachingLiteDBPackageVersion> | ||
<EasyCachingCorePackageVersion>1.1.0</EasyCachingCorePackageVersion> | ||
<EasyCachingMemcachedPackageVersion>1.1.0</EasyCachingMemcachedPackageVersion> | ||
<EasyCachingRedisPackageVersion>1.1.0</EasyCachingRedisPackageVersion> | ||
<EasyCachingSQLitePackageVersion>1.1.0</EasyCachingSQLitePackageVersion> | ||
<EasyCachingInMemoryPackageVersion>1.1.0</EasyCachingInMemoryPackageVersion> | ||
<EasyCachingHybridPackageVersion>1.1.0</EasyCachingHybridPackageVersion> | ||
<EasyCachingAspectCorePackageVersion>1.1.0</EasyCachingAspectCorePackageVersion> | ||
<EasyCachingCastlePackageVersion>1.1.0</EasyCachingCastlePackageVersion> | ||
<EasyCachingResponseCachingPackageVersion>1.1.0</EasyCachingResponseCachingPackageVersion> | ||
<EasyCachingJsonPackageVersion>1.1.0</EasyCachingJsonPackageVersion> | ||
<EasyCachingMessagePackPackageVersion>1.1.0</EasyCachingMessagePackPackageVersion> | ||
<EasyCachingProtobufPackageVersion>1.1.0</EasyCachingProtobufPackageVersion> | ||
<EasyCachingCSRedisPackageVersion>1.1.0</EasyCachingCSRedisPackageVersion> | ||
<EasyCachingRedisBusPackageVersion>1.1.0</EasyCachingRedisBusPackageVersion> | ||
<EasyCachingCSRedisBusPackageVersion>1.1.0</EasyCachingCSRedisBusPackageVersion> | ||
<EasyCachingRabbitBusPackageVersion>1.1.0</EasyCachingRabbitBusPackageVersion> | ||
<EasyCachingDiskPackageVersion>1.1.0</EasyCachingDiskPackageVersion> | ||
<EasyCachingMsExtPackageVersion>1.1.0</EasyCachingMsExtPackageVersion> | ||
<EasyCachingLiteDBPackageVersion>1.1.0</EasyCachingLiteDBPackageVersion> | ||
<EasyCachingSTJsonPackageVersion>1.1.0</EasyCachingSTJsonPackageVersion> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...syCaching.Serialization.SystemTextJson/Configurations/EasyCachingJsonSerializerOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.Encodings.Web; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace EasyCaching.Serialization.SystemTextJson.Configurations | ||
{ | ||
public class EasyCachingJsonSerializerOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets the encoder to use when escaping strings, or null to use the default | ||
/// encoder. | ||
/// </summary> | ||
public JavaScriptEncoder Encoder => JavaScriptEncoder.UnsafeRelaxedJsonEscaping; | ||
/// <summary> | ||
/// Gets or sets a value that defines how comments are handled during deserialization. | ||
/// </summary> | ||
public JsonCommentHandling ReadCommentHandling => JsonCommentHandling.Disallow; | ||
/// <summary> | ||
/// Gets or sets a value that specifies the policy used to convert a property's name | ||
/// on an object to another format, such as camel-casing, or null to leave property | ||
/// names unchanged. | ||
/// </summary> | ||
public JsonNamingPolicy PropertyNamingPolicy => null; | ||
/// <summary> | ||
/// Gets or sets a value that determines whether a property's name uses a case-insensitive | ||
/// comparison during deserialization. The default value is false. | ||
/// </summary> | ||
public bool PropertyNameCaseInsensitive => false; | ||
/// <summary> | ||
/// Specifies how number types should be handled when serializing or deserializing. | ||
/// </summary> | ||
public JsonNumberHandling NumberHandling => JsonNumberHandling.Strict; | ||
/// <summary> | ||
/// Gets or sets the maximum depth allowed when serializing or deserializing JSON, | ||
/// with the default value of 0 indicating a maximum depth of 64. | ||
/// </summary> | ||
public int MaxDepth => 0; | ||
/// <summary> | ||
/// Determines whether fields are handled serialization and deserialization. The | ||
/// default value is false. | ||
/// </summary> | ||
public bool IncludeFields => false; | ||
/// <summary> | ||
/// Gets a value that determines whether read-only properties are ignored during | ||
/// serialization. The default value is false. | ||
/// </summary> | ||
public bool IgnoreReadOnlyProperties => false; | ||
/// <summary> | ||
/// Determines whether read-only fields are ignored during serialization. A property | ||
/// is read-only if it isn't marked with the readonly keyword. The default value is false. | ||
/// </summary> | ||
public bool IgnoreReadOnlyFields => false; | ||
/// <summary> | ||
/// Gets or sets a value that determines whether null values are ignored during serialization | ||
/// and deserialization. The default value is false. | ||
/// </summary> | ||
public bool IgnoreNullValues = false; | ||
/// <summary> | ||
/// Gets or sets the policy used to convert a System.Collections.IDictionary key's | ||
/// name to another format, such as camel-casing. | ||
/// </summary> | ||
public JsonNamingPolicy DictionaryKeyPolicy => null; | ||
/// <summary> | ||
/// Specifies a condition to determine when properties with default values are ignored | ||
/// during serialization or deserialization. The default value is System.Text.Json.Serialization.JsonIgnoreCondition.Never. | ||
/// </summary> | ||
public JsonIgnoreCondition DefaultIgnoreCondition => JsonIgnoreCondition.Never; | ||
/// <summary> | ||
/// Gets or sets the default buffer size, in bytes, to use when creating temporary buffers. | ||
/// </summary> | ||
public int DefaultBufferSize => 16 * 1024; | ||
/// <summary> | ||
/// Gets the list of user-defined converters that were registered. | ||
/// </summary> | ||
public IList<JsonConverter> Converters => new List<JsonConverter>(); | ||
/// <summary> | ||
/// Get or sets a value that indicates whether an extra comma at the end of a list | ||
/// of JSON values in an object or array is allowed (and ignored) within the JSON | ||
/// payload being deserialized. | ||
/// </summary> | ||
public bool AllowTrailingCommas => false; | ||
/// <summary> | ||
/// Configures how object references are handled when reading and writing JSON. | ||
/// </summary> | ||
public ReferenceHandler ReferenceHandler => null; | ||
/// <summary> | ||
/// Gets or sets a value that defines whether JSON should use pretty printing. By | ||
/// default, JSON is serialized without any extra white space. | ||
/// </summary> | ||
public bool WriteIndented => false; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...n/EasyCaching.Serialization.SystemTextJson/Configurations/EasyCachingOptionsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using EasyCaching.Core.Configurations; | ||
using System; | ||
using System.Linq; | ||
using System.Text.Json; | ||
|
||
namespace EasyCaching.Serialization.SystemTextJson.Configurations | ||
{ | ||
|
||
/// <summary> | ||
/// EasyCaching options extensions. | ||
/// </summary> | ||
public static class EasyCachingOptionsExtensions | ||
{ | ||
/// <summary> | ||
/// Withs the json serializer. | ||
/// </summary> | ||
/// <param name="options">Options.</param> | ||
/// <param name="name">The name of this serializer instance.</param> | ||
public static EasyCachingOptions WithSystemTextJson(this EasyCachingOptions options, string name = "json") => options.WithSystemTextJson(configure: x => { }, name); | ||
|
||
/// <summary> | ||
/// Withs the json serializer. | ||
/// </summary> | ||
/// <param name="options">Options.</param> | ||
/// <param name="configure">Configure serializer settings.</param> | ||
/// <param name="name">The name of this serializer instance.</param> | ||
public static EasyCachingOptions WithSystemTextJson(this EasyCachingOptions options, Action<EasyCachingJsonSerializerOptions> configure, string name) | ||
{ | ||
var easyCachingJsonSerializerOptions = new EasyCachingJsonSerializerOptions(); | ||
|
||
configure(easyCachingJsonSerializerOptions); | ||
|
||
void jsonSerializerSettings(JsonSerializerOptions x) | ||
{ | ||
x.MaxDepth = easyCachingJsonSerializerOptions.MaxDepth; | ||
x.AllowTrailingCommas = easyCachingJsonSerializerOptions.AllowTrailingCommas; | ||
x.Converters.Union(easyCachingJsonSerializerOptions.Converters); | ||
x.DefaultBufferSize = easyCachingJsonSerializerOptions.DefaultBufferSize; | ||
x.DefaultIgnoreCondition = easyCachingJsonSerializerOptions.DefaultIgnoreCondition; | ||
x.DictionaryKeyPolicy = easyCachingJsonSerializerOptions.DictionaryKeyPolicy; | ||
x.Encoder = easyCachingJsonSerializerOptions.Encoder; | ||
x.IgnoreReadOnlyFields = easyCachingJsonSerializerOptions.IgnoreReadOnlyFields; | ||
x.IgnoreReadOnlyProperties = easyCachingJsonSerializerOptions.IgnoreReadOnlyProperties; | ||
x.IncludeFields = easyCachingJsonSerializerOptions.IncludeFields; | ||
x.NumberHandling = easyCachingJsonSerializerOptions.NumberHandling; | ||
x.PropertyNameCaseInsensitive = easyCachingJsonSerializerOptions.PropertyNameCaseInsensitive; | ||
x.PropertyNamingPolicy = easyCachingJsonSerializerOptions.PropertyNamingPolicy; | ||
x.ReadCommentHandling = easyCachingJsonSerializerOptions.ReadCommentHandling; | ||
x.ReferenceHandler = easyCachingJsonSerializerOptions.ReferenceHandler; | ||
x.WriteIndented = easyCachingJsonSerializerOptions.WriteIndented; | ||
} | ||
|
||
options.RegisterExtension(new JsonOptionsExtension(name, jsonSerializerSettings)); | ||
|
||
return options; | ||
} | ||
|
||
/// <summary> | ||
/// Withs the json serializer. | ||
/// </summary> | ||
/// <param name="options">Options.</param> | ||
/// <param name="jsonSerializerSettingsConfigure">Configure serializer settings.</param> | ||
/// <param name="name">The name of this serializer instance.</param> | ||
public static EasyCachingOptions WithSystemTextJson(this EasyCachingOptions options, Action<JsonSerializerOptions> jsonSerializerSettingsConfigure, string name) | ||
{ | ||
options.RegisterExtension(new JsonOptionsExtension(name, jsonSerializerSettingsConfigure)); | ||
|
||
return options; | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...alization/EasyCaching.Serialization.SystemTextJson/Configurations/JsonOptionsExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using EasyCaching.Core.Configurations; | ||
using EasyCaching.Core.Serialization; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using System.Text.Json; | ||
|
||
namespace EasyCaching.Serialization.SystemTextJson | ||
{ | ||
/// <summary> | ||
/// Json options extension. | ||
/// </summary> | ||
internal sealed class JsonOptionsExtension : IEasyCachingOptionsExtension | ||
{ | ||
/// <summary> | ||
/// The name. | ||
/// </summary> | ||
private readonly string _name; | ||
|
||
/// <summary> | ||
/// The configure. | ||
/// </summary> | ||
private readonly Action<JsonSerializerOptions> _configure; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="T:EasyCaching.Serialization.SystemTextJson.JsonOptionsExtension"/> class. | ||
/// </summary> | ||
/// <param name="name">Name.</param> | ||
/// <param name="configure">Configure.</param> | ||
public JsonOptionsExtension(string name, Action<JsonSerializerOptions> configure) | ||
{ | ||
_name = name; | ||
_configure = configure; | ||
} | ||
|
||
public void AddServices(IServiceCollection services) | ||
{ | ||
Action<JsonSerializerOptions> configure = x => { }; | ||
|
||
if (_configure != null) configure = _configure; | ||
|
||
services.AddOptions(); | ||
services.Configure(_name, configure); | ||
services.AddSingleton<IEasyCachingSerializer, DefaultJsonSerializer>(x => | ||
{ | ||
var optionsMon = x.GetRequiredService<Microsoft.Extensions.Options.IOptionsMonitor<JsonSerializerOptions>>(); | ||
var options = optionsMon.Get(_name); | ||
return new DefaultJsonSerializer(_name, options); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.