Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmwebb-lv committed Jul 30, 2024
1 parent ef15d91 commit 1bb5a3c
Show file tree
Hide file tree
Showing 30 changed files with 507 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\RCommon.MemoryCache\RCommon.MemoryCache.csproj" />
<ProjectReference Include="..\..\..\Src\RCommon.MemoryCache\RCommon.MemoryCache.csproj" />
</ItemGroup>

</Project>
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();
}
}
12 changes: 5 additions & 7 deletions Examples/Caching/Examples.Caching.MemoryCaching/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
.WithCaching<MemoryCachingBuilder>(cache =>
{

// Or this way which uses a little magic but is simple
cqrs.AddCommandHandlers((typeof(Program).GetTypeInfo().Assembly));
cqrs.AddQueryHandlers((typeof(Program).GetTypeInfo().Assembly));

});

services.AddTransient<ITestApplicationService, TestApplicationService>();
Expand All @@ -35,11 +33,11 @@

Console.WriteLine("Example Starting");
var appService = host.Services.GetRequiredService<ITestApplicationService>();
var commandResult = await appService(new TestCommand("test"));
var queryResult = await appService.ExecuteTestQuery(new TestQuery());
await appService.SetCache();
await appService.GetCache();

Console.WriteLine(commandResult.ToString());
Console.WriteLine(queryResult.Message);
Console.WriteLine("");
Console.WriteLine("");

Console.WriteLine("Example Complete");
Console.ReadLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

namespace Examples.Caching.MemoryCaching
{
public class TestApplicationService
public class TestApplicationService : ITestApplicationService
{

public TestApplicationService()
{

}

public async Task SetCache()
{

}

public async Task GetCache()
{

}
}
}
14 changes: 14 additions & 0 deletions Examples/Json/Examples.Json.JsonNet/ConfigurationContainer.cs
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; }
}
}
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);
}
}
54 changes: 52 additions & 2 deletions Examples/Json/Examples.Json.JsonNet/Program.cs
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 Examples/Json/Examples.Json.JsonNet/TestApplicationService.cs
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);
}
}
}
18 changes: 18 additions & 0 deletions Examples/Json/Examples.Json.JsonNet/TestDto.cs
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; }
}
}
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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Src\RCommon.SystemTextJson\RCommon.SystemTextJson.csproj" />
</ItemGroup>

</Project>
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);
}
}
52 changes: 50 additions & 2 deletions Examples/Json/Examples.Json.SystemTextJson/Program.cs
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());

}

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);
}
}
}
18 changes: 18 additions & 0 deletions Examples/Json/Examples.Json.SystemTextJson/TestDto.cs
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; }
}
}
3 changes: 1 addition & 2 deletions Src/RCommon.Caching/CachingBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ public static IRCommonBuilder WithCaching<T>(this IRCommonBuilder builder, Actio
where T : ICachingBuilder
{
Guard.IsNotNull(actions, nameof(actions));

// Event Handling Configurations
var cachingConfig = (T)Activator.CreateInstance(typeof(T), new object[] { builder });
actions(cachingConfig);
return builder;
}

}
}
6 changes: 3 additions & 3 deletions Src/RCommon.Json/IJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace RCommon.Json
{
public interface IJsonSerializer
{
public string Serialize(object obj, JsonSerializeOptions options);
public string Serialize(object obj, JsonSerializeOptions? options = null);

public T Deserialize<T>(string json, JsonDeserializeOptions options);
public T Deserialize<T>(string json, JsonDeserializeOptions? options = null);

public object Deserialize(Type type, string json, JsonDeserializeOptions options);
public object Deserialize(string json, Type type, JsonDeserializeOptions? options = null);
}
}
Loading

0 comments on commit 1bb5a3c

Please sign in to comment.