diff --git a/Data.sln b/Data.sln index 53790f1..87300b7 100644 --- a/Data.sln +++ b/Data.sln @@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data", "Powered EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data.MongoDB", "PoweredSoft.Data.MongoDB\PoweredSoft.Data.MongoDB.csproj", "{34BED188-2B88-4CAD-8DD0-6FC70D156902}" 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 Global 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}.Release|Any CPU.ActiveCfg = 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 GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PoweredSoft.Data.InMemory/InMemoryQueryableHandlerService.cs b/PoweredSoft.Data.InMemory/InMemoryQueryableHandlerService.cs new file mode 100644 index 0000000..788a18a --- /dev/null +++ b/PoweredSoft.Data.InMemory/InMemoryQueryableHandlerService.cs @@ -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 AnyAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) + { + return Task.FromResult(queryable.Any(predicate)); + } + + public Task AnyAsync(IQueryable queryable, CancellationToken cancellationToken = default) + { + return Task.FromResult(queryable.Any()); + } + + public bool CanHandle(IQueryable queryable) + { + var result = queryable is EnumerableQuery; + return result; + } + + public Task CountAsync(IQueryable queryable, CancellationToken cancellationToken = default) + { + return Task.FromResult(queryable.Count()); + } + + public Task FirstOrDefaultAsync(IQueryable queryable, CancellationToken cancellationToken = default) + { + return Task.FromResult(queryable.FirstOrDefault()); + } + + public Task FirstOrDefaultAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default) + { + return Task.FromResult(queryable.FirstOrDefault(predicate)); + } + + public Task LongCountAsync(IQueryable queryable, CancellationToken cancellationToken = default) + { + return Task.FromResult(queryable.LongCount()); + } + + public Task> ToListAsync(IQueryable queryable, CancellationToken cancellationToken = default) + { + return Task.FromResult(queryable.ToList()); + } + } +} diff --git a/PoweredSoft.Data.InMemory/PoweredSoft.Data.InMemory.csproj b/PoweredSoft.Data.InMemory/PoweredSoft.Data.InMemory.csproj new file mode 100644 index 0000000..5cd297b --- /dev/null +++ b/PoweredSoft.Data.InMemory/PoweredSoft.Data.InMemory.csproj @@ -0,0 +1,27 @@ + + + + netstandard2.0 + True + Powered Softwares Inc. + MIT + https://github.com/PoweredSoft/Data + https://github.com/PoweredSoft/Data + github + async,queryable,handler,service,di + 2.0.0$(VersionSuffix) + https://secure.gravatar.com/avatar/4e32f73820c16718909a06c2927f1f8b?s=512&r=g&d=retro + PoweredSoft.Data.InMemory + Library to abstract orm. + PoweredSoft.Data.InMemory + N/A + False + PoweredSoft + David Lebee + + + + + + + diff --git a/PoweredSoft.Data.InMemory/ServiceCollectionExtensions.cs b/PoweredSoft.Data.InMemory/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..05b2e69 --- /dev/null +++ b/PoweredSoft.Data.InMemory/ServiceCollectionExtensions.cs @@ -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(); + return services; + } + } +}