in memory.
This commit is contained in:
parent
39d86b9804
commit
8b2c82bb5a
8
Data.sln
8
Data.sln
@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data", "Powered
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data.MongoDB", "PoweredSoft.Data.MongoDB\PoweredSoft.Data.MongoDB.csproj", "{34BED188-2B88-4CAD-8DD0-6FC70D156902}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data.MongoDB", "PoweredSoft.Data.MongoDB\PoweredSoft.Data.MongoDB.csproj", "{34BED188-2B88-4CAD-8DD0-6FC70D156902}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.Data.EntityFramework", "PoweredSoft.Data.EntityFramework\PoweredSoft.Data.EntityFramework.csproj", "{7BB489B2-58C0-4C49-A339-70E4CE750A40}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data.EntityFramework", "PoweredSoft.Data.EntityFramework\PoweredSoft.Data.EntityFramework.csproj", "{7BB489B2-58C0-4C49-A339-70E4CE750A40}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.Data.InMemory", "PoweredSoft.Data.InMemory\PoweredSoft.Data.InMemory.csproj", "{48BD4248-F908-4F69-BCAE-2BC312F33CBD}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -45,6 +47,10 @@ Global
|
|||||||
{7BB489B2-58C0-4C49-A339-70E4CE750A40}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{7BB489B2-58C0-4C49-A339-70E4CE750A40}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{7BB489B2-58C0-4C49-A339-70E4CE750A40}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{7BB489B2-58C0-4C49-A339-70E4CE750A40}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{7BB489B2-58C0-4C49-A339-70E4CE750A40}.Release|Any CPU.Build.0 = Release|Any CPU
|
{7BB489B2-58C0-4C49-A339-70E4CE750A40}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{48BD4248-F908-4F69-BCAE-2BC312F33CBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{48BD4248-F908-4F69-BCAE-2BC312F33CBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{48BD4248-F908-4F69-BCAE-2BC312F33CBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{48BD4248-F908-4F69-BCAE-2BC312F33CBD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
54
PoweredSoft.Data.InMemory/InMemoryQueryableHandlerService.cs
Normal file
54
PoweredSoft.Data.InMemory/InMemoryQueryableHandlerService.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using PoweredSoft.Data.Core;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PoweredSoft.Data.InMemory
|
||||||
|
{
|
||||||
|
public class InMemoryQueryableHandlerService : IAsyncQueryableHandlerService
|
||||||
|
{
|
||||||
|
public Task<bool> AnyAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return Task.FromResult(queryable.Any(predicate));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> AnyAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return Task.FromResult(queryable.Any());
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanHandle<T>(IQueryable<T> queryable)
|
||||||
|
{
|
||||||
|
var result = queryable is EnumerableQuery<T>;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<int> CountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return Task.FromResult(queryable.Count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return Task.FromResult(queryable.FirstOrDefault());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return Task.FromResult(queryable.FirstOrDefault(predicate));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<long> LongCountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return Task.FromResult(queryable.LongCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<List<T>> ToListAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return Task.FromResult(queryable.ToList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
PoweredSoft.Data.InMemory/PoweredSoft.Data.InMemory.csproj
Normal file
27
PoweredSoft.Data.InMemory/PoweredSoft.Data.InMemory.csproj
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
|
<Copyright>Powered Softwares Inc.</Copyright>
|
||||||
|
<PackageLicenseUrl>MIT</PackageLicenseUrl>
|
||||||
|
<PackageProjectUrl>https://github.com/PoweredSoft/Data</PackageProjectUrl>
|
||||||
|
<RepositoryUrl>https://github.com/PoweredSoft/Data</RepositoryUrl>
|
||||||
|
<RepositoryType>github</RepositoryType>
|
||||||
|
<PackageTags>async,queryable,handler,service,di</PackageTags>
|
||||||
|
<Version>2.0.0$(VersionSuffix)</Version>
|
||||||
|
<PackageIconUrl>https://secure.gravatar.com/avatar/4e32f73820c16718909a06c2927f1f8b?s=512&amp;r=g&amp;d=retro</PackageIconUrl>
|
||||||
|
<Product>PoweredSoft.Data.InMemory</Product>
|
||||||
|
<Description>Library to abstract orm.</Description>
|
||||||
|
<PackageId>PoweredSoft.Data.InMemory</PackageId>
|
||||||
|
<PackageReleaseNotes>N/A</PackageReleaseNotes>
|
||||||
|
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
|
||||||
|
<Company>PoweredSoft</Company>
|
||||||
|
<Authors>David Lebee</Authors>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PoweredSoft.Data\PoweredSoft.Data.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
19
PoweredSoft.Data.InMemory/ServiceCollectionExtensions.cs
Normal file
19
PoweredSoft.Data.InMemory/ServiceCollectionExtensions.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
|
using PoweredSoft.Data.Core;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PoweredSoft.Data.InMemory
|
||||||
|
{
|
||||||
|
public static class ServiceCollectionExtensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddPoweredSoftInMemoryDataServices(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddPoweredSoftDataServices();
|
||||||
|
services.AddTransient<IAsyncQueryableHandlerService, InMemoryQueryableHandlerService>();
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user