diff --git a/DragonFruit.Common.Data/ApiClient.cs b/DragonFruit.Common.Data/ApiClient.cs index c58f83d..8c025bc 100644 --- a/DragonFruit.Common.Data/ApiClient.cs +++ b/DragonFruit.Common.Data/ApiClient.cs @@ -12,6 +12,7 @@ using DragonFruit.Common.Data.Exceptions; using DragonFruit.Common.Data.Headers; using DragonFruit.Common.Data.Serializers; +using DragonFruit.Common.Data.Utils; #pragma warning disable 618 @@ -25,19 +26,12 @@ public class ApiClient #region Constructors /// - /// Initialises a new using an using the + /// Initialises a new using an with an optional /// - public ApiClient() - : this(new ApiJsonSerializer(CultureInfo.InvariantCulture)) - { - } - - /// - /// Initialises a new using an using a custom - /// - public ApiClient(CultureInfo culture) - : this(new ApiJsonSerializer(culture)) + public ApiClient(CultureInfo culture = null) + : this(new ApiJsonSerializer()) { + Serializer.Configure(o => o.Serializer.Culture = culture ?? CultureUtils.DefaultCulture); } /// @@ -415,4 +409,20 @@ public void RequestClientReset(bool fullReset) [MethodImpl(MethodImplOptions.AggressiveInlining)] protected void RequestFinished() => _lock.ExitReadLock(); } + + /// + /// A superclass designed to allow better serializer configuration + /// + /// The to use + public class ApiClient : ApiClient where T : ApiSerializer, new() + { + public ApiClient(Action configurationOptions = null) + : base(Activator.CreateInstance()) + { + if (configurationOptions != null) + { + Serializer.Configure(configurationOptions); + } + } + } } diff --git a/DragonFruit.Common.Data/Serializers/SerializerResolver.cs b/DragonFruit.Common.Data/Serializers/SerializerResolver.cs index 6a3684a..fa73c18 100644 --- a/DragonFruit.Common.Data/Serializers/SerializerResolver.cs +++ b/DragonFruit.Common.Data/Serializers/SerializerResolver.cs @@ -14,7 +14,6 @@ public class SerializerResolver private static readonly Dictionary SerializerMap = new Dictionary(); private static readonly Dictionary DeserializerMap = new Dictionary(); - private ISerializer _default; private readonly ConcurrentDictionary _serializerCache = new ConcurrentDictionary(); /// @@ -67,21 +66,9 @@ public static void Unregister(DataDirection direction = DataDirection.All) } /// - /// The default to use + /// The default in use. /// - public ISerializer Default - { - get => _default; - set - { - if (value is ApiSerializer { IsGeneric: false }) - { - throw new ArgumentException("The provided serializer is non-generic."); - } - - _default = value; - } - } + public ISerializer Default { get; } /// /// Resolves the for the type provided