Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmwebb-lv committed Jul 31, 2024
1 parent 1bb5a3c commit eb06ba6
Show file tree
Hide file tree
Showing 18 changed files with 166 additions and 65 deletions.
7 changes: 7 additions & 0 deletions Examples/Examples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RCommon.SystemTextJson", ".
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RCommon.MemoryCache", "..\Src\RCommon.MemoryCache\RCommon.MemoryCache.csproj", "{F5277287-1776-494B-92EE-7237D1B8949B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCommon.DistibutedMemoryCache", "..\Src\RCommon.DistibutedMemoryCache\RCommon.DistibutedMemoryCache.csproj", "{0BCA99B2-86A4-40DF-B42D-7AD9F8BC4C49}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -375,6 +377,10 @@ Global
{F5277287-1776-494B-92EE-7237D1B8949B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5277287-1776-494B-92EE-7237D1B8949B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5277287-1776-494B-92EE-7237D1B8949B}.Release|Any CPU.Build.0 = Release|Any CPU
{0BCA99B2-86A4-40DF-B42D-7AD9F8BC4C49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0BCA99B2-86A4-40DF-B42D-7AD9F8BC4C49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BCA99B2-86A4-40DF-B42D-7AD9F8BC4C49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BCA99B2-86A4-40DF-B42D-7AD9F8BC4C49}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -435,6 +441,7 @@ Global
{8F5C5AD3-8310-47A7-BB30-42C054D032E2} = {A53F8891-29D2-449D-B9BA-062D19EC7834}
{6C07FC1A-4339-42AA-AF5F-83570F81A5A4} = {3199F749-0082-41D0-91D3-ECED117F8B08}
{F5277287-1776-494B-92EE-7237D1B8949B} = {3199F749-0082-41D0-91D3-ECED117F8B08}
{0BCA99B2-86A4-40DF-B42D-7AD9F8BC4C49} = {3199F749-0082-41D0-91D3-ECED117F8B08}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B0CD26D-8067-4667-863E-6B0EE7EDAA42}
Expand Down
29 changes: 23 additions & 6 deletions Src/RCommon.Caching/CachingBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using RCommon.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -8,14 +10,29 @@ namespace RCommon.Caching
{
public static class CachingBuilderExtensions
{
public static IRCommonBuilder WithCaching<T>(this IRCommonBuilder builder)
where T : ICachingBuilder
public static IRCommonBuilder WithMemoryCaching<T>(this IRCommonBuilder builder)
where T : IMemoryCachingBuilder
{
return WithCaching<T>(builder, x => { });
return WithMemoryCaching<T>(builder, x => { });
}

public static IRCommonBuilder WithCaching<T>(this IRCommonBuilder builder, Action<T> actions)
where T : ICachingBuilder
public static IRCommonBuilder WithMemoryCaching<T>(this IRCommonBuilder 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 IRCommonBuilder WithDistributedCaching<T>(this IRCommonBuilder builder)
where T : IDistributedCachingBuilder
{
return WithDistributedCaching<T>(builder, x => { });
}

public static IRCommonBuilder WithDistributedCaching<T>(this IRCommonBuilder builder, Action<T> actions)
where T : IDistributedCachingBuilder
{
Guard.IsNotNull(actions, nameof(actions));
var cachingConfig = (T)Activator.CreateInstance(typeof(T), new object[] { builder });
Expand Down
12 changes: 0 additions & 12 deletions Src/RCommon.Caching/ICachingService.cs

This file was deleted.

14 changes: 14 additions & 0 deletions Src/RCommon.Caching/IDistributedCachingBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.Caching
{
public interface IDistributedCachingBuilder
{
IServiceCollection Services { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace RCommon.Caching
{
public interface ICachingBuilder
public interface IMemoryCachingBuilder
{
IServiceCollection Services { get; }
}
Expand Down
1 change: 1 addition & 0 deletions Src/RCommon.Caching/RCommon.Caching.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

</Project>
25 changes: 25 additions & 0 deletions Src/RCommon.MemoryCache/DistributedMemoryCacheBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.MemoryCache
{
public class DistributedMemoryCacheBuilder : IDistributedMemoryCachingBuilder
{
public DistributedMemoryCacheBuilder(IRCommonBuilder builder)
{
Services = builder.Services;
this.RegisterServices(Services);
}

protected void RegisterServices(IServiceCollection services)
{

}

public IServiceCollection Services { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using RCommon.Caching;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.MemoryCache
{
public static class IMemoryCachingBuilderExtensions
public interface IDistributedMemoryCachingBuilder : IDistributedCachingBuilder
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using RCommon.Caching;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.MemoryCache
{
public static class IDistributedMemoryCachingBuilderExtensions
{
public static IDistributedMemoryCachingBuilder Configure(this IDistributedMemoryCachingBuilder builder, Action<MemoryDistributedCacheOptions> actions)
{
builder.Services.AddDistributedMemoryCache(actions);
return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace RCommon.MemoryCache
{
public interface IMemoryCachingBuilder : ICachingBuilder
public interface IInMemoryCachingBuilder : IMemoryCachingBuilder
{
}
}
19 changes: 19 additions & 0 deletions Src/RCommon.MemoryCache/IInMemoryCachingBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.MemoryCache
{
public static class IInMemoryCachingBuilderExtensions
{
public static IInMemoryCachingBuilder Configure(this IInMemoryCachingBuilder builder, Action<MemoryCacheOptions> actions)
{
builder.Services.AddMemoryCache(actions);
return builder;
}
}
}
20 changes: 0 additions & 20 deletions Src/RCommon.MemoryCache/MemoryCacheService.cs

This file was deleted.

16 changes: 14 additions & 2 deletions Src/RCommon.MemoryCache/MemoryCachingBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using RCommon.Caching;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -7,8 +8,19 @@

namespace RCommon.MemoryCache
{
public class MemoryCachingBuilder : IMemoryCachingBuilder
public class MemoryCachingBuilder : IInMemoryCachingBuilder
{
public IServiceCollection Services => throw new NotImplementedException();
public MemoryCachingBuilder(IRCommonBuilder builder)
{
Services = builder.Services;
this.RegisterServices(Services);
}

protected void RegisterServices(IServiceCollection services)
{

}

public IServiceCollection Services { get; }
}
}
2 changes: 1 addition & 1 deletion Src/RCommon.RedisCache/IRedisCachingBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace RCommon.RedisCache
{
public interface IRedisCachingBuilder : ICachingBuilder
public interface IRedisCachingBuilder : IDistributedCachingBuilder
{
}
}
9 changes: 8 additions & 1 deletion Src/RCommon.RedisCache/IRedisCachingBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -8,5 +10,10 @@ namespace RCommon.RedisCache
{
public static class IRedisCachingBuilderExtensions
{
public static IRedisCachingBuilder Configure(this IRedisCachingBuilder builder, Action<RedisCacheOptions> actions)
{
builder.Services.AddStackExchangeRedisCache(actions);
return builder;
}
}
}
17 changes: 0 additions & 17 deletions Src/RCommon.RedisCache/RedisCacheService.cs

This file was deleted.

18 changes: 16 additions & 2 deletions Src/RCommon.RedisCache/RedisCachingBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using RCommon.Caching;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.RedisCache
{
public static class RedisCachingBuilder
public class RedisCachingBuilder : IDistributedCachingBuilder
{
public RedisCachingBuilder(IRCommonBuilder builder)
{
Services = builder.Services;
this.RegisterServices(Services);
}

protected void RegisterServices(IServiceCollection services)
{

}

public IServiceCollection Services { get; }
}
}

0 comments on commit eb06ba6

Please sign in to comment.