diff --git a/serialization/EasyCaching.Serialization.MemoryPack/Configurations/EasyCachingMemPackSerializerOptions.cs b/serialization/EasyCaching.Serialization.MemoryPack/Configurations/EasyCachingMemPackSerializerOptions.cs
index 033aa04d..e7748658 100644
--- a/serialization/EasyCaching.Serialization.MemoryPack/Configurations/EasyCachingMemPackSerializerOptions.cs
+++ b/serialization/EasyCaching.Serialization.MemoryPack/Configurations/EasyCachingMemPackSerializerOptions.cs
@@ -7,7 +7,11 @@ namespace EasyCaching.Serialization.MemoryPack;
///
public record EasyCachingMemPackSerializerOptions
{
- public StringEncoding StringEncoding { set; get; }
+ ///
+ /// Gets or sets the string encoding. (Defaults to )
+ ///
+ ///
+ /// The string encoding.
+ ///
+ public StringEncoding StringEncoding { set; get; } = StringEncoding.Utf8;
}
-
-
diff --git a/serialization/EasyCaching.Serialization.MemoryPack/Configurations/EasyCachingOptionsExtensions.cs b/serialization/EasyCaching.Serialization.MemoryPack/Configurations/EasyCachingOptionsExtensions.cs
index 0585d747..2373b277 100644
--- a/serialization/EasyCaching.Serialization.MemoryPack/Configurations/EasyCachingOptionsExtensions.cs
+++ b/serialization/EasyCaching.Serialization.MemoryPack/Configurations/EasyCachingOptionsExtensions.cs
@@ -1,8 +1,7 @@
-using MemoryPack;
-using EasyCaching.Core.Configurations;
-using EasyCaching.Serialization.Json;
+using EasyCaching.Core.Configurations;
+using EasyCaching.Serialization.MemoryPack;
-namespace EasyCaching.Serialization.MemoryPack;
+namespace Microsoft.Extensions.DependencyInjection;
///
/// Easy caching options extensions.
@@ -13,7 +12,7 @@ public static class EasyCachingOptionsExtensions
/// Withs the memory pack serializer.
///
/// Options.
- /// The name of this serializer instance.
+ /// The name of this serializer instance.
public static EasyCachingOptions WithMemoryPack(this EasyCachingOptions options, string name = "mempack")
{
options.RegisterExtension(new MemoryPackOptionsExtension(name, null));
@@ -23,10 +22,10 @@ public static EasyCachingOptions WithMemoryPack(this EasyCachingOptions options,
///
/// Withs the memory pack serializer.
- ///
+ ///
/// Options.
/// Configure serializer settings.
- /// The name of this serializer instance.
+ /// The name of this serializer instance.
public static EasyCachingOptions WithMemoryPack(this EasyCachingOptions options, Action serializerOptions, string name)
{
options.RegisterExtension(new MemoryPackOptionsExtension(name, serializerOptions));
diff --git a/serialization/EasyCaching.Serialization.MemoryPack/Configurations/MemoryPackOptionsExtension.cs b/serialization/EasyCaching.Serialization.MemoryPack/Configurations/MemoryPackOptionsExtension.cs
index 58126711..d0983f1a 100644
--- a/serialization/EasyCaching.Serialization.MemoryPack/Configurations/MemoryPackOptionsExtension.cs
+++ b/serialization/EasyCaching.Serialization.MemoryPack/Configurations/MemoryPackOptionsExtension.cs
@@ -1,12 +1,10 @@
-namespace EasyCaching.Serialization.Json;
-
-using System;
using EasyCaching.Core.Configurations;
using EasyCaching.Core.Serialization;
-using EasyCaching.Serialization.MemoryPack;
-using global::MemoryPack;
+using MemoryPack;
using Microsoft.Extensions.DependencyInjection;
+namespace EasyCaching.Serialization.MemoryPack;
+
///
/// MemoryPack options extension.
///
@@ -29,8 +27,8 @@ internal sealed class MemoryPackOptionsExtension : IEasyCachingOptionsExtension
/// Configure.
public MemoryPackOptionsExtension(string name, Action configure)
{
- this._name = name;
- this._configure = configure;
+ _name = name;
+ _configure = configure;
}
///
@@ -44,11 +42,16 @@ public void AddServices(IServiceCollection services)
services.AddOptions();
services.Configure(_name, configure);
- services.AddSingleton(x =>
+ services.AddSingleton(services =>
{
- var optionsMon = x.GetRequiredService>();
+ var optionsMon = services.GetRequiredService>();
var easyCachingOptions = optionsMon.Get(_name);
- var options = new MemoryPackSerializerOptions { StringEncoding = easyCachingOptions.StringEncoding };
+
+ var options = MemoryPackSerializerOptions.Default;
+ typeof(MemoryPackSerializerOptions)
+ .GetProperty(nameof(MemoryPackSerializerOptions.StringEncoding))
+ .SetValue(options, easyCachingOptions.StringEncoding);
+
return new DefaultMemoryPackSerializer(_name, options);
});
}