Inspired by dotnet show (#386)
* Changed the order of the projects, Web first to infer as startup. * Added encapsulated JSON serialization - and moved to System.Text.Json * Refactored a few minor updates out Co-authored-by: Eric Fleming <eric-fleming18@hotmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
<PackageReference Include="Ardalis.GuardClauses" Version="1.5.0" />
|
||||
<PackageReference Include="Ardalis.Specification" Version="3.0.0" />
|
||||
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="4.7.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
18
src/ApplicationCore/Extensions/JsonExtensions.cs
Normal file
18
src/ApplicationCore/Extensions/JsonExtensions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Microsoft.eShopWeb
|
||||
{
|
||||
public static class JsonExtensions
|
||||
{
|
||||
private static readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
public static T FromJson<T>(this string json) =>
|
||||
JsonSerializer.Deserialize<T>(json, _jsonOptions);
|
||||
|
||||
public static string ToJson<T>(this T obj) =>
|
||||
JsonSerializer.Serialize<T>(obj, _jsonOptions);
|
||||
}
|
||||
}
|
||||
@@ -172,16 +172,15 @@ namespace Microsoft.eShopWeb.Web
|
||||
{
|
||||
ResponseWriter = async (context, report) =>
|
||||
{
|
||||
var result = JsonConvert.SerializeObject(
|
||||
new
|
||||
var result = new
|
||||
{
|
||||
status = report.Status.ToString(),
|
||||
errors = report.Entries.Select(e => new
|
||||
{
|
||||
status = report.Status.ToString(),
|
||||
errors = report.Entries.Select(e => new
|
||||
{
|
||||
key = e.Key,
|
||||
value = Enum.GetName(typeof(HealthStatus), e.Value.Status)
|
||||
})
|
||||
});
|
||||
key = e.Key,
|
||||
value = Enum.GetName(typeof(HealthStatus), e.Value.Status)
|
||||
})
|
||||
}.ToJson();
|
||||
context.Response.ContentType = MediaTypeNames.Application.Json;
|
||||
await context.Response.WriteAsync(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user