Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmwebb-lv committed Jul 27, 2024
1 parent 5f8a667 commit 787a6cc
Show file tree
Hide file tree
Showing 9 changed files with 400 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Examples/Examples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RCommon.FluentValidation",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Validation", "Validation", "{0F54DCE2-27A5-4D07-B542-6D2A7B50D0EC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples.Validation.FluentValidation", "Validation\Examples.Validation.FluentValidation\Examples.Validation.FluentValidation.csproj", "{256821F9-8160-4819-B0A1-B769C5BBBBB6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.Validation.FluentValidation", "Validation\Examples.Validation.FluentValidation\Examples.Validation.FluentValidation.csproj", "{256821F9-8160-4819-B0A1-B769C5BBBBB6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCommon.Persistence.Caching", "..\Src\RCommon.Persistence.Caching\RCommon.Persistence.Caching.csproj", "{B66429EB-4B5F-42F9-9CD7-7334190A14F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCommon.DistributedMemoryCache", "..\Src\RCommon.DistributedMemoryCache\RCommon.DistributedMemoryCache.csproj", "{DCF81616-F849-46BF-B7DE-1B30798418D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCommon.RedisCache", "RCommon.RedisCache\RCommon.RedisCache.csproj", "{6F9A2678-49D1-4626-B0AF-176B95AF3A72}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -299,6 +305,18 @@ Global
{256821F9-8160-4819-B0A1-B769C5BBBBB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{256821F9-8160-4819-B0A1-B769C5BBBBB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{256821F9-8160-4819-B0A1-B769C5BBBBB6}.Release|Any CPU.Build.0 = Release|Any CPU
{B66429EB-4B5F-42F9-9CD7-7334190A14F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B66429EB-4B5F-42F9-9CD7-7334190A14F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B66429EB-4B5F-42F9-9CD7-7334190A14F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B66429EB-4B5F-42F9-9CD7-7334190A14F4}.Release|Any CPU.Build.0 = Release|Any CPU
{DCF81616-F849-46BF-B7DE-1B30798418D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DCF81616-F849-46BF-B7DE-1B30798418D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCF81616-F849-46BF-B7DE-1B30798418D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCF81616-F849-46BF-B7DE-1B30798418D0}.Release|Any CPU.Build.0 = Release|Any CPU
{6F9A2678-49D1-4626-B0AF-176B95AF3A72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F9A2678-49D1-4626-B0AF-176B95AF3A72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F9A2678-49D1-4626-B0AF-176B95AF3A72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F9A2678-49D1-4626-B0AF-176B95AF3A72}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -348,6 +366,8 @@ Global
{BBBCCC2B-2218-4C32-96EE-C2153A23F643} = {3199F749-0082-41D0-91D3-ECED117F8B08}
{0F54DCE2-27A5-4D07-B542-6D2A7B50D0EC} = {3234C3BB-1632-4684-838E-9D6D382D4D4D}
{256821F9-8160-4819-B0A1-B769C5BBBBB6} = {0F54DCE2-27A5-4D07-B542-6D2A7B50D0EC}
{DCF81616-F849-46BF-B7DE-1B30798418D0} = {3199F749-0082-41D0-91D3-ECED117F8B08}
{6F9A2678-49D1-4626-B0AF-176B95AF3A72} = {3199F749-0082-41D0-91D3-ECED117F8B08}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B0CD26D-8067-4667-863E-6B0EE7EDAA42}
Expand Down
9 changes: 9 additions & 0 deletions Examples/RCommon.RedisCache/RCommon.RedisCache.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

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

</Project>
176 changes: 176 additions & 0 deletions Src/RCommon.Persistence.Caching/Crud/CachingGraphRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
using RCommon.Collections;
using RCommon.Entities;
using RCommon.Persistence.Crud;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.Persistence.Caching.Crud
{
public class CachingGraphRepository<TEntity> : IGraphRepository<TEntity>
where TEntity : class, IBusinessEntity
{
private readonly IGraphRepository<TEntity> _graphRepository;
private readonly IOptions<PersistenceCachingOptions> _cachingConfiguration;
private readonly IDistributedCache _distributedCache;

public CachingGraphRepository(IGraphRepository<TEntity> graphRepository, IOptions<PersistenceCachingOptions> cachingConfiguration,
IDistributedCache distributedCache)
{
_graphRepository = graphRepository;
_cachingConfiguration = cachingConfiguration;
_distributedCache = distributedCache;
}

public bool Tracking { get => _graphRepository.Tracking; set => _graphRepository.Tracking = value; }

public Type ElementType => _graphRepository.ElementType;

public Expression Expression => _graphRepository.Expression;

public IQueryProvider Provider => _graphRepository.Provider;

public string DataStoreName { get => _graphRepository.DataStoreName; set => _graphRepository.DataStoreName = value; }

public async Task AddAsync(TEntity entity, CancellationToken token = default)
{
await _graphRepository.AddAsync(entity, token);
}

public async Task<bool> AnyAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default)
{
return await _graphRepository.AnyAsync(expression, token);
}

public async Task<bool> AnyAsync(ISpecification<TEntity> specification, CancellationToken token = default)
{
return await _graphRepository.AnyAsync(specification, token);
}

public async Task DeleteAsync(TEntity entity, CancellationToken token = default)
{
await _graphRepository.DeleteAsync(entity, token);
}

public async Task<TEntity> FindAsync(object primaryKey, CancellationToken token = default)
{
return await _graphRepository.FindAsync(primaryKey, token);
}

public IQueryable<TEntity> FindQuery(ISpecification<TEntity> specification)
{
return _graphRepository.FindQuery(specification);
}

public IQueryable<TEntity> FindQuery(Expression<Func<TEntity, bool>> expression)
{
return _graphRepository.FindQuery(expression);
}

public IQueryable<TEntity> FindQuery(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, object>> orderByExpression, bool orderByAscending, int pageNumber = 1, int pageSize = 0)
{
return _graphRepository.FindQuery(expression, orderByExpression, orderByAscending, pageNumber, pageSize);
}

public IQueryable<TEntity> FindQuery(IPagedSpecification<TEntity> specification)
{
return _graphRepository.FindQuery(specification);
}

public async Task<TEntity> FindSingleOrDefaultAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default)
{
return await _graphRepository.FindSingleOrDefaultAsync(expression, token);
}

public async Task<TEntity> FindSingleOrDefaultAsync(ISpecification<TEntity> specification, CancellationToken token = default)
{
return await _graphRepository.FindSingleOrDefaultAsync(specification, token);
}

public async Task<long> GetCountAsync(ISpecification<TEntity> selectSpec, CancellationToken token = default)
{
return await _graphRepository.GetCountAsync(selectSpec, token);
}

public async Task<long> GetCountAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default)
{
return await _graphRepository.GetCountAsync(expression, token);
}

public IEnumerator<TEntity> GetEnumerator()
{
return _graphRepository.GetEnumerator();
}

public IEagerLoadableQueryable<TEntity> Include(Expression<Func<TEntity, object>> path)
{
return _graphRepository.Include(path);
}

public IEagerLoadableQueryable<TEntity> ThenInclude<TPreviousProperty, TProperty>(Expression<Func<object, TProperty>> path)
{
return _graphRepository.ThenInclude<TPreviousProperty, TProperty>(path);
}

public async Task UpdateAsync(TEntity entity, CancellationToken token = default)
{
await _graphRepository.UpdateAsync(entity, token);
}

IEnumerator IEnumerable.GetEnumerator()
{
return _graphRepository.GetEnumerator();
}

public async Task<IPaginatedList<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity,
object>> orderByExpression, bool orderByAscending, int pageNumber = 1, int pageSize = 0, CancellationToken token = default)
{
return await _graphRepository.FindAsync(expression, orderByExpression, orderByAscending, pageNumber, pageSize, token);
}

public async Task<IPaginatedList<TEntity>> FindAsync(IPagedSpecification<TEntity> specification, CancellationToken token = default)
{
return await _graphRepository.FindAsync(specification, token);
}

public async Task<ICollection<TEntity>> FindAsync(ISpecification<TEntity> specification, CancellationToken token = default)
{
return await _graphRepository.FindAsync(specification, token);
}

public async Task<ICollection<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default)
{
return await _graphRepository.FindAsync(expression, token);
}

// Cached items

public async Task<IPaginatedList<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity,
object>> orderByExpression, bool orderByAscending, string cacheKey, int pageNumber = 1, int pageSize = 0, CancellationToken token = default)
{
if (_distributedCache.get)
return await _graphRepository.FindAsync(expression, orderByExpression, orderByAscending, pageNumber, pageSize, token);
}

public async Task<IPaginatedList<TEntity>> FindAsync(IPagedSpecification<TEntity> specification, CancellationToken token = default)
{
return await _graphRepository.FindAsync(specification, token);
}

public async Task<ICollection<TEntity>> FindAsync(ISpecification<TEntity> specification, CancellationToken token = default)
{
return await _graphRepository.FindAsync(specification, token);
}

public async Task<ICollection<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default)
{
return await _graphRepository.FindAsync(expression, token);
}
}
}
135 changes: 135 additions & 0 deletions Src/RCommon.Persistence.Caching/Crud/CachingLinqRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using RCommon.Collections;
using RCommon.Entities;
using RCommon.Persistence.Crud;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.Persistence.Caching.Crud
{
public class CachingLinqRepository<TEntity> : ILinqRepository<TEntity>
where TEntity : class, IBusinessEntity
{
public Type ElementType => throw new NotImplementedException();

public Expression Expression => throw new NotImplementedException();

public IQueryProvider Provider => throw new NotImplementedException();

public string DataStoreName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

public Task AddAsync(TEntity entity, CancellationToken token = default)
{
throw new NotImplementedException();
}

public Task<bool> AnyAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default)
{
throw new NotImplementedException();
}

public Task<bool> AnyAsync(ISpecification<TEntity> specification, CancellationToken token = default)
{
throw new NotImplementedException();
}

public Task DeleteAsync(TEntity entity, CancellationToken token = default)
{
throw new NotImplementedException();
}

public Task<IPaginatedList<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, object>> orderByExpression, bool orderByAscending, int pageNumber = 1, int pageSize = 0, CancellationToken token = default)
{
throw new NotImplementedException();
}

public Task<IPaginatedList<TEntity>> FindAsync(IPagedSpecification<TEntity> specification, CancellationToken token = default)
{
throw new NotImplementedException();
}

public Task<ICollection<TEntity>> FindAsync(ISpecification<TEntity> specification, CancellationToken token = default)
{
throw new NotImplementedException();
}

public Task<ICollection<TEntity>> FindAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default)
{
throw new NotImplementedException();
}

public Task<TEntity> FindAsync(object primaryKey, CancellationToken token = default)
{
throw new NotImplementedException();
}

public IQueryable<TEntity> FindQuery(ISpecification<TEntity> specification)
{
throw new NotImplementedException();
}

public IQueryable<TEntity> FindQuery(Expression<Func<TEntity, bool>> expression)
{
throw new NotImplementedException();
}

public IQueryable<TEntity> FindQuery(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, object>> orderByExpression, bool orderByAscending, int pageNumber = 1, int pageSize = 0)
{
throw new NotImplementedException();
}

public IQueryable<TEntity> FindQuery(IPagedSpecification<TEntity> specification)
{
throw new NotImplementedException();
}

public Task<TEntity> FindSingleOrDefaultAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default)
{
throw new NotImplementedException();
}

public Task<TEntity> FindSingleOrDefaultAsync(ISpecification<TEntity> specification, CancellationToken token = default)
{
throw new NotImplementedException();
}

public Task<long> GetCountAsync(ISpecification<TEntity> selectSpec, CancellationToken token = default)
{
throw new NotImplementedException();
}

public Task<long> GetCountAsync(Expression<Func<TEntity, bool>> expression, CancellationToken token = default)
{
throw new NotImplementedException();
}

public IEnumerator<TEntity> GetEnumerator()
{
throw new NotImplementedException();
}

public IEagerLoadableQueryable<TEntity> Include(Expression<Func<TEntity, object>> path)
{
throw new NotImplementedException();
}

public IEagerLoadableQueryable<TEntity> ThenInclude<TPreviousProperty, TProperty>(Expression<Func<object, TProperty>> path)
{
throw new NotImplementedException();
}

public Task UpdateAsync(TEntity entity, CancellationToken token = default)
{
throw new NotImplementedException();
}

IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
}
12 changes: 12 additions & 0 deletions Src/RCommon.Persistence.Caching/Crud/CachingSqlMapperRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RCommon.Persistence.Caching.Crud
{
public class CachingSqlMapperRepository
{
}
}
Loading

0 comments on commit 787a6cc

Please sign in to comment.