-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef15d91
commit 1bb5a3c
Showing
30 changed files
with
507 additions
and
37 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
9 changes: 9 additions & 0 deletions
9
Examples/Caching/Examples.Caching.MemoryCaching/ITestApplicationService.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,9 @@ | ||
| ||
namespace Examples.Caching.MemoryCaching | ||
{ | ||
public interface ITestApplicationService | ||
{ | ||
Task GetCache(); | ||
Task SetCache(); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
Examples/Json/Examples.Json.JsonNet/ConfigurationContainer.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,14 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Examples.Json.JsonNet | ||
{ | ||
internal static class ConfigurationContainer | ||
{ | ||
public static IConfiguration Configuration { get; set; } | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
Examples/Json/Examples.Json.JsonNet/ITestApplicationService.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,8 @@ | ||
namespace Examples.Json.JsonNet | ||
{ | ||
public interface ITestApplicationService | ||
{ | ||
TestDto Deserialize(string json); | ||
string Serialize(TestDto testDto); | ||
} | ||
} |
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,2 +1,52 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
Console.WriteLine("Hello, World!"); | ||
using Examples.Json.JsonNet; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using RCommon; | ||
using RCommon.Json; | ||
using RCommon.JsonNet; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
using Newtonsoft.Json; | ||
|
||
try | ||
{ | ||
var host = Host.CreateDefaultBuilder(args) | ||
.ConfigureAppConfiguration((context, builder) => | ||
{ | ||
|
||
ConfigurationContainer.Configuration = builder | ||
.Build(); | ||
}) | ||
.ConfigureServices(services => | ||
{ | ||
// Configure RCommon | ||
services.AddRCommon() | ||
.WithJsonSerialization<JsonNetBuilder>(json => | ||
{ | ||
|
||
json.CamelCase = true; | ||
json.Indented = true; | ||
}); | ||
|
||
services.AddTransient<ITestApplicationService, TestApplicationService>(); | ||
|
||
}).Build(); | ||
|
||
Console.WriteLine("Example Starting"); | ||
var appService = host.Services.GetRequiredService<ITestApplicationService>(); | ||
string json = appService.Serialize(new TestDto("This is my ")); | ||
TestDto dto = appService.Deserialize("{ // TestDto\r\n \"message\": This is my deserialized message\r\n}"); | ||
|
||
Console.WriteLine(json); | ||
Console.WriteLine(dto.Message); | ||
|
||
Console.WriteLine("Example Complete"); | ||
Console.ReadLine(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.ToString()); | ||
|
||
} | ||
|
29 changes: 29 additions & 0 deletions
29
Examples/Json/Examples.Json.JsonNet/TestApplicationService.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,29 @@ | ||
using RCommon.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Examples.Json.JsonNet | ||
{ | ||
public class TestApplicationService : ITestApplicationService | ||
{ | ||
private readonly IJsonSerializer _serializer; | ||
|
||
public TestApplicationService(IJsonSerializer serializer) | ||
{ | ||
_serializer = serializer; | ||
} | ||
|
||
public string Serialize(TestDto testDto) | ||
{ | ||
return _serializer.Serialize(testDto); | ||
} | ||
|
||
public TestDto Deserialize(string json) | ||
{ | ||
return _serializer.Deserialize<TestDto>(json); | ||
} | ||
} | ||
} |
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,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Examples.Json.JsonNet | ||
{ | ||
public class TestDto | ||
{ | ||
public TestDto(string message) | ||
{ | ||
Message = message; | ||
} | ||
|
||
public string Message { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Examples/Json/Examples.Json.SystemTextJson/ConfigurationContainer.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,14 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Examples.Json.SystemTextJson | ||
{ | ||
internal static class ConfigurationContainer | ||
{ | ||
public static IConfiguration Configuration { get; set; } | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
Examples/Json/Examples.Json.SystemTextJson/ITestApplicationService.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,8 @@ | ||
namespace Examples.Json.SystemTextJson | ||
{ | ||
public interface ITestApplicationService | ||
{ | ||
TestDto Deserialize(string json); | ||
string Serialize(TestDto testDto); | ||
} | ||
} |
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,2 +1,50 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
Console.WriteLine("Hello, World!"); | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using RCommon; | ||
using RCommon.Json; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
using Examples.Json.SystemTextJson; | ||
using RCommon.SystemTextJson; | ||
|
||
try | ||
{ | ||
var host = Host.CreateDefaultBuilder(args) | ||
.ConfigureAppConfiguration((context, builder) => | ||
{ | ||
|
||
ConfigurationContainer.Configuration = builder | ||
.Build(); | ||
}) | ||
.ConfigureServices(services => | ||
{ | ||
// Configure RCommon | ||
services.AddRCommon() | ||
.WithJsonSerialization<TextJsonBuilder>(json => | ||
{ | ||
json.CamelCase = true; | ||
json.Indented = true; | ||
}); | ||
|
||
services.AddTransient<ITestApplicationService, TestApplicationService>(); | ||
|
||
}).Build(); | ||
|
||
Console.WriteLine("Example Starting"); | ||
var appService = host.Services.GetRequiredService<ITestApplicationService>(); | ||
string json = appService.Serialize(new TestDto("This is my ")); | ||
TestDto dto = appService.Deserialize("{ // TestDto\r\n \"message\": This is my deserialized message\r\n}"); | ||
|
||
Console.WriteLine(json); | ||
Console.WriteLine(dto.Message); | ||
|
||
Console.WriteLine("Example Complete"); | ||
Console.ReadLine(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.ToString()); | ||
|
||
} | ||
|
29 changes: 29 additions & 0 deletions
29
Examples/Json/Examples.Json.SystemTextJson/TestApplicationService.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,29 @@ | ||
using RCommon.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Examples.Json.SystemTextJson | ||
{ | ||
public class TestApplicationService : ITestApplicationService | ||
{ | ||
private readonly IJsonSerializer _serializer; | ||
|
||
public TestApplicationService(IJsonSerializer serializer) | ||
{ | ||
_serializer = serializer; | ||
} | ||
|
||
public string Serialize(TestDto testDto) | ||
{ | ||
return _serializer.Serialize(testDto); | ||
} | ||
|
||
public TestDto Deserialize(string json) | ||
{ | ||
return _serializer.Deserialize<TestDto>(json); | ||
} | ||
} | ||
} |
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,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Examples.Json.SystemTextJson | ||
{ | ||
public class TestDto | ||
{ | ||
public TestDto(string message) | ||
{ | ||
Message = message; | ||
} | ||
|
||
public string Message { get; set; } | ||
} | ||
} |
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
Oops, something went wrong.