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 93eced3 commit ef15d91
Show file tree
Hide file tree
Showing 39 changed files with 706 additions and 18 deletions.
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.Caching.MemoryCaching
{
internal static class ConfigurationContainer
{
public static IConfiguration Configuration { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

</Project>
52 changes: 52 additions & 0 deletions Examples/Caching/Examples.Caching.MemoryCaching/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Examples.Caching.MemoryCaching;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RCommon;
using RCommon.Caching;
using RCommon.MemoryCache;
using System.Diagnostics;
using System.Reflection;

try
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, builder) =>
{

ConfigurationContainer.Configuration = builder
.Build();
})
.ConfigureServices(services =>
{
// Configure RCommon
services.AddRCommon()
.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>();

}).Build();

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

Console.WriteLine(commandResult.ToString());
Console.WriteLine(queryResult.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,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Examples.Caching.MemoryCaching
{
public class TestApplicationService
{

public TestApplicationService()
{

}

public async Task SetCache()
{

}

public async Task GetCache()
{

}
}
}
18 changes: 18 additions & 0 deletions Examples/Caching/Examples.Caching.MemoryCaching/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.Caching.MemoryCaching
{
public record TestDto
{
public TestDto(string message)
{
Message = message;
}

public string Message { get; }
}
}
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.Caching.PersistenceCaching
{
internal static class ConfigurationContainer
{
public static IConfiguration Configuration { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

</Project>
67 changes: 67 additions & 0 deletions Examples/Caching/Examples.Caching.PersistenceCaching/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Examples.ApplicationServices.CQRS.Validators;
using Examples.Caching.PersistenceCaching;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RCommon;
using RCommon.ApplicationServices;
using RCommon.ApplicationServices.ExecutionResults;
using RCommon.FluentValidation;
using System.Diagnostics;
using System.Reflection;

try
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, builder) =>
{

ConfigurationContainer.Configuration = builder
.Build();
})
.ConfigureServices(services =>
{
// Configure RCommon
services.AddRCommon()
.WithCQRS<CqrsBuilder>(cqrs =>
{
// You can do it this way which is pretty straight forward but verbose
//cqrs.AddQueryHandler<TestQueryHandler, TestQuery, TestDto>();
//cqrs.AddCommandHandler<TestCommandHandler, TestCommand, IExecutionResult>();

// Or this way which uses a little magic but is simple
cqrs.AddCommandHandlers((typeof(Program).GetTypeInfo().Assembly));
cqrs.AddQueryHandlers((typeof(Program).GetTypeInfo().Assembly));
})
.WithValidation<FluentValidationBuilder>(validation =>
{
validation.AddValidatorsFromAssemblyContaining(typeof(TestCommand));

validation.UseWithCqrs(options =>
{
options.ValidateCommands = true;
options.ValidateQueries = true;
});
});

services.AddTransient<ITestApplicationService, TestApplicationService>();

}).Build();

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

Console.WriteLine(commandResult.ToString());
Console.WriteLine(queryResult.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,33 @@
using RCommon.ApplicationServices.Commands;
using RCommon.ApplicationServices.ExecutionResults;
using RCommon.ApplicationServices.Queries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Examples.Caching.PersistenceCaching
{
public class TestApplicationService : ITestApplicationService
{
private readonly ICommandBus _commandBus;
private readonly IQueryBus _queryBus;

public TestApplicationService(ICommandBus commandBus, IQueryBus queryBus)
{
_commandBus = commandBus;
_queryBus = queryBus;
}

public async Task<TestDto> ExecuteTestQuery(TestQuery query)
{
return await _queryBus.DispatchQueryAsync(query, CancellationToken.None);
}

public async Task<IExecutionResult> ExecuteTestCommand(TestCommand command)
{
return await _commandBus.DispatchCommandAsync(command, CancellationToken.None);
}
}
}
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.Caching.RedisCaching
{
internal static class ConfigurationContainer
{
public static IConfiguration Configuration { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

</Project>
67 changes: 67 additions & 0 deletions Examples/Caching/Examples.Caching.RedisCaching/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Examples.ApplicationServices.CQRS.Validators;
using Examples.Caching.RedisCaching;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RCommon;
using RCommon.ApplicationServices;
using RCommon.ApplicationServices.ExecutionResults;
using RCommon.FluentValidation;
using System.Diagnostics;
using System.Reflection;

try
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, builder) =>
{

ConfigurationContainer.Configuration = builder
.Build();
})
.ConfigureServices(services =>
{
// Configure RCommon
services.AddRCommon()
.WithCQRS<CqrsBuilder>(cqrs =>
{
// You can do it this way which is pretty straight forward but verbose
//cqrs.AddQueryHandler<TestQueryHandler, TestQuery, TestDto>();
//cqrs.AddCommandHandler<TestCommandHandler, TestCommand, IExecutionResult>();

// Or this way which uses a little magic but is simple
cqrs.AddCommandHandlers((typeof(Program).GetTypeInfo().Assembly));
cqrs.AddQueryHandlers((typeof(Program).GetTypeInfo().Assembly));
})
.WithValidation<FluentValidationBuilder>(validation =>
{
validation.AddValidatorsFromAssemblyContaining(typeof(TestCommand));

validation.UseWithCqrs(options =>
{
options.ValidateCommands = true;
options.ValidateQueries = true;
});
});

services.AddTransient<ITestApplicationService, TestApplicationService>();

}).Build();

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

Console.WriteLine(commandResult.ToString());
Console.WriteLine(queryResult.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,33 @@
using RCommon.ApplicationServices.Commands;
using RCommon.ApplicationServices.ExecutionResults;
using RCommon.ApplicationServices.Queries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Examples.Caching.RedisCaching
{
public class TestApplicationService : ITestApplicationService
{
private readonly ICommandBus _commandBus;
private readonly IQueryBus _queryBus;

public TestApplicationService(ICommandBus commandBus, IQueryBus queryBus)
{
_commandBus = commandBus;
_queryBus = queryBus;
}

public async Task<TestDto> ExecuteTestQuery(TestQuery query)
{
return await _queryBus.DispatchQueryAsync(query, CancellationToken.None);
}

public async Task<IExecutionResult> ExecuteTestCommand(TestCommand command)
{
return await _commandBus.DispatchCommandAsync(command, CancellationToken.None);
}
}
}
Loading

0 comments on commit ef15d91

Please sign in to comment.