async handler with better cohabitaton logic.

This commit is contained in:
David Lebee
2019-02-13 20:01:47 -06:00
parent 50f3bfee93
commit 828f868fe4
18 changed files with 330 additions and 18 deletions
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query.Internal;
using PoweredSoft.Data.Core;
using System;
using System.Collections.Generic;
@@ -9,7 +10,7 @@ using System.Threading.Tasks;
namespace PoweredSoft.Data.EntityFrameworkCore
{
public class AsyncQueryableFactory : IAsyncQueryableFactory
public class AsyncQueryableHandlerService : IAsyncQueryableHandlerService
{
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
=> queryable.FirstOrDefaultAsync(cancellationToken);
@@ -21,5 +22,13 @@ namespace PoweredSoft.Data.EntityFrameworkCore
=> queryable.CountAsync();
public Task<long> LongCountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
=> queryable.LongCountAsync();
public bool CanHandle<T>(IQueryable<T> queryable) => queryable.Provider is IAsyncQueryProvider;
public Task<bool> AnyAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
=> queryable.AnyAsync(predicate, cancellationToken);
public Task<bool> AnyAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
=> queryable.AnyAsync(cancellationToken);
}
}
@@ -13,7 +13,6 @@ namespace PoweredSoft.Data.EntityFrameworkCore
public class DbContextFactory : IDbContextFactory
{
private readonly DbContext _context;
private MethodInfo _setGenericMethod = null;
public DbContextFactory(DbContext dbContext)
{
@@ -9,17 +9,15 @@
<RepositoryUrl>https://github.com/PoweredSoft/Data</RepositoryUrl>
<RepositoryType>github</RepositoryType>
<PackageTags>powered,soft,orm,db,context,ef,ef6,efcore,factory</PackageTags>
<Version>1.0.2</Version>
<Version>1.1.0</Version>
<PackageIconUrl>https://secure.gravatar.com/avatar/4e32f73820c16718909a06c2927f1f8b?s=512&amp;amp;r=g&amp;amp;d=retro</PackageIconUrl>
<Product>PoweredSoft.Data.EntityFrameworkCore</Product>
<Description>the abstraction implementation for EF Core.</Description>
<PackageId>PoweredSoft.Data.EntityFrameworkCore</PackageId>
<PackageReleaseNotes>added support of resolve primary keys.</PackageReleaseNotes>
<PackageReleaseNotes>N/A</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<Company>PoweredSoft.Data.EntityFrameworkCore</Company>
<Authors>PoweredSoft.Data.EntityFrameworkCore</Authors>
<AssemblyVersion>1.0.2.0</AssemblyVersion>
<FileVersion>1.0.2.0</FileVersion>
<Company>PoweredSoft</Company>
<Authors>David Lebee</Authors>
</PropertyGroup>
<ItemGroup>
@@ -28,6 +26,7 @@
<ItemGroup>
<ProjectReference Include="..\PoweredSoft.Data.Core\PoweredSoft.Data.Core.csproj" />
<ProjectReference Include="..\PoweredSoft.Data\PoweredSoft.Data.csproj" />
</ItemGroup>
</Project>
@@ -9,10 +9,11 @@ namespace PoweredSoft.Data.EntityFrameworkCore
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddPoweredSoftDataServices(this IServiceCollection services)
public static IServiceCollection AddPoweredSoftEntityFrameworkCoreDataServices(this IServiceCollection services)
{
services.AddPoweredSoftDataServices();
services.TryAddTransient<IDbContextFactoryProvider, DbContextFactoryProvider>();
services.TryAddTransient<IAsyncQueryableFactory, AsyncQueryableFactory>();
services.TryAddTransient<IAsyncQueryableHandlerService, AsyncQueryableHandlerService>();
return services;
}
}