Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmwebb-lv committed Aug 12, 2024
1 parent be56169 commit e6c5343
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using RCommon;
using RCommon.ApplicationServices;
using RCommon.ApplicationServices.ExecutionResults;
using RCommon.Caching;
using RCommon.FluentValidation;
using System.Diagnostics;
using System.Reflection;
Expand All @@ -32,6 +33,7 @@
// Or this way which uses a little magic but is simple
cqrs.AddCommandHandlers((typeof(Program).GetTypeInfo().Assembly));
cqrs.AddQueryHandlers((typeof(Program).GetTypeInfo().Assembly));
cqrs.AddMemoryCachingForHandlers<IMemoryCachingBuilder>();
})
.WithValidation<FluentValidationBuilder>(validation =>
{
Expand Down
3 changes: 3 additions & 0 deletions Examples/Caching/Examples.Caching.MemoryCaching/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Microsoft.Extensions.Hosting;
using RCommon;
using RCommon.Caching;
using RCommon.Json;
using RCommon.JsonNet;
using RCommon.MemoryCache;
using System.Diagnostics;
using System.Reflection;
Expand All @@ -21,6 +23,7 @@
{
// Configure RCommon
services.AddRCommon()
.WithJsonSerialization<JsonNetBuilder>()
.WithMemoryCaching<MemoryCachingBuilder>(cache =>
{
cache.Configure(x =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
.ConfigureServices(services =>
{
// Configure RCommon
services.AddRCommon();
services.AddRCommon()
.WithJsonSerialization<JsonNetBuilder>();
services.AddTransient<ITestApplicationService, TestApplicationService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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

Expand Down
3 changes: 3 additions & 0 deletions Examples/Caching/Examples.Caching.RedisCaching/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Examples.Caching.RedisCaching;
using RCommon.Json;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RCommon;
using RCommon.Caching;
using RCommon.JsonNet;
using RCommon.RedisCache;
using System.Diagnostics;
using System.Reflection;
Expand All @@ -21,6 +23,7 @@
{
// Configure RCommon
services.AddRCommon()
.WithJsonSerialization<JsonNetBuilder>()
.WithDistributedCaching<RedisCachingBuilder>(cache =>
{
cache.Configure(redis =>
Expand Down
18 changes: 18 additions & 0 deletions Src/RCommon.ApplicationServices/CqrsCachingOptions.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 RCommon.ApplicationServices
{
public class CqrsCachingOptions
{
public CqrsCachingOptions()
{
this.UseCacheForHandlers = false;
}

public bool UseCacheForHandlers { get; set; }
}
}
42 changes: 42 additions & 0 deletions Src/RCommon.ApplicationServices/ICqrsBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using RCommon.Caching;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.ApplicationServices
{
public static class ICqrsBuilderExtensions
{
public static ICqrsBuilder AddMemoryCachingForHandlers<T>(this ICqrsBuilder builder)
where T : IMemoryCachingBuilder
{
return AddMemoryCachingForHandlers<T>(builder, x => { });
}

public static ICqrsBuilder AddMemoryCachingForHandlers<T>(this ICqrsBuilder builder, Action<T> actions)
where T : IMemoryCachingBuilder
{
Guard.IsNotNull(actions, nameof(actions));
var cachingConfig = (T)Activator.CreateInstance(typeof(T), new object[] { builder });
actions(cachingConfig);
return builder;
}

public static ICqrsBuilder AddDistributedCachingForHandlers<T>(this ICqrsBuilder builder)
where T : IDistributedCachingBuilder
{
return AddDistributedCachingForHandlers<T>(builder, x => { });
}

public static ICqrsBuilder AddDistributedCachingForHandlers<T>(this ICqrsBuilder builder, Action<T> actions)
where T : IDistributedCachingBuilder
{
Guard.IsNotNull(actions, nameof(actions));
var cachingConfig = (T)Activator.CreateInstance(typeof(T), new object[] { builder });
actions(cachingConfig);
return builder;
}
}
}
1 change: 1 addition & 0 deletions Src/RCommon.ApplicationServices/Queries/QueryBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public async Task<TResult> DispatchQueryAsync<TResult>(IQuery<TResult> query, Ca

private CacheItem GetCacheItem(Type queryType)
{
if
return _memoryCache.GetOrCreate(
CacheKey.With(GetType(), queryType.GetCacheKey()),
e =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\RCommon.Caching\RCommon.Caching.csproj" />
<ProjectReference Include="..\RCommon.Core\RCommon.Core.csproj" />
<ProjectReference Include="..\RCommon.Entities\RCommon.Entities.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
8 changes: 3 additions & 5 deletions Src/RCommon.Caching/RCommon.Caching.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
Expand Down
8 changes: 3 additions & 5 deletions Src/RCommon.Json/RCommon.Json.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
Expand Down
8 changes: 3 additions & 5 deletions Src/RCommon.JsonNet/RCommon.JsonNet.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
Expand Down
8 changes: 3 additions & 5 deletions Src/RCommon.MemoryCache/RCommon.MemoryCache.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\RCommon.Caching\RCommon.Caching.csproj" />
Expand Down
8 changes: 3 additions & 5 deletions Src/RCommon.RedisCache/RCommon.RedisCache.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.7" />
Expand Down
8 changes: 3 additions & 5 deletions Src/RCommon.SystemTextJson/RCommon.SystemTextJson.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
Expand Down

0 comments on commit e6c5343

Please sign in to comment.