refactor: refinamentos

This commit is contained in:
Jean Gatto
2023-09-17 15:34:25 -03:00
parent 2e14a5d778
commit 9eff92145c
3 changed files with 16 additions and 4 deletions
+2
View File
@@ -183,6 +183,8 @@ visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public
# .NET Diagnostic # # .NET Diagnostic #
############################### ###############################
[*.{cs,vb}]
# Simplify name # Simplify name
dotnet_diagnostic.IDE0001.severity = warning dotnet_diagnostic.IDE0001.severity = warning
+4 -3
View File
@@ -8,7 +8,8 @@ namespace Shop.Core.Extensions;
public static class JsonExtensions public static class JsonExtensions
{ {
private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions().Configure(); private static readonly Lazy<JsonSerializerOptions> LazyOptions =
new(() => new JsonSerializerOptions().Configure(), isThreadSafe: true);
/// <summary> /// <summary>
/// Converts a JSON string to an object of type T. /// Converts a JSON string to an object of type T.
@@ -17,7 +18,7 @@ public static class JsonExtensions
/// <param name="value">The JSON string to deserialize.</param> /// <param name="value">The JSON string to deserialize.</param>
/// <returns>The deserialized object of type T.</returns> /// <returns>The deserialized object of type T.</returns>
public static T FromJson<T>(this string value) => public static T FromJson<T>(this string value) =>
value != null ? JsonSerializer.Deserialize<T>(value, JsonOptions) : default; value != null ? JsonSerializer.Deserialize<T>(value, LazyOptions.Value) : default;
/// <summary> /// <summary>
/// Converts an object to JSON string. /// Converts an object to JSON string.
@@ -26,7 +27,7 @@ public static class JsonExtensions
/// <param name="value">The object to convert.</param> /// <param name="value">The object to convert.</param>
/// <returns>The JSON string representation of the object.</returns> /// <returns>The JSON string representation of the object.</returns>
public static string ToJson<T>(this T value) => public static string ToJson<T>(this T value) =>
value != null ? JsonSerializer.Serialize(value, JsonOptions) : default; value != null ? JsonSerializer.Serialize(value, LazyOptions.Value) : default;
/// <summary> /// <summary>
/// Configures the JsonSerializerOptions instance. /// Configures the JsonSerializerOptions instance.
@@ -35,7 +35,16 @@ internal static class ServicesCollectionExtensions
{ {
Version = "v1", Version = "v1",
Title = "Shop (e-commerce)", Title = "Shop (e-commerce)",
Description = "ASP.NET Core C# CQRS Event Sourcing, REST API, DDD, SOLID Principles and Clean Architecture" Description = "ASP.NET Core C# CQRS Event Sourcing, REST API, DDD, SOLID Principles and Clean Architecture",
Contact = new OpenApiContact
{
Name = "Jean Gatto",
Email = "jean_gatto@hotmail.com"
},
License = new OpenApiLicense
{
Name = "MIT License"
}
}); });
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";