in memory.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user