-
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
93eced3
commit ef15d91
Showing
39 changed files
with
706 additions
and
18 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
Examples/Caching/Examples.Caching.MemoryCaching/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.Caching.MemoryCaching | ||
{ | ||
internal static class ConfigurationContainer | ||
{ | ||
public static IConfiguration Configuration { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Examples/Caching/Examples.Caching.MemoryCaching/Examples.Caching.MemoryCaching.csproj
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 @@ | ||
<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
52
Examples/Caching/Examples.Caching.MemoryCaching/Program.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,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()); | ||
|
||
} | ||
|
27 changes: 27 additions & 0 deletions
27
Examples/Caching/Examples.Caching.MemoryCaching/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,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
18
Examples/Caching/Examples.Caching.MemoryCaching/TestDto.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,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; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Examples/Caching/Examples.Caching.PersistenceCaching/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.Caching.PersistenceCaching | ||
{ | ||
internal static class ConfigurationContainer | ||
{ | ||
public static IConfiguration Configuration { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...es/Caching/Examples.Caching.PersistenceCaching/Examples.Caching.PersistenceCaching.csproj
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 @@ | ||
<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
67
Examples/Caching/Examples.Caching.PersistenceCaching/Program.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,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()); | ||
|
||
} | ||
|
33 changes: 33 additions & 0 deletions
33
Examples/Caching/Examples.Caching.PersistenceCaching/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,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); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Examples/Caching/Examples.Caching.RedisCaching/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.Caching.RedisCaching | ||
{ | ||
internal static class ConfigurationContainer | ||
{ | ||
public static IConfiguration Configuration { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Examples/Caching/Examples.Caching.RedisCaching/Examples.Caching.RedisCaching.csproj
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 @@ | ||
<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> |
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,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()); | ||
|
||
} | ||
|
33 changes: 33 additions & 0 deletions
33
Examples/Caching/Examples.Caching.RedisCaching/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,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); | ||
} | ||
} | ||
} |
Oops, something went wrong.