diff --git a/Data.sln b/Data.sln index 9bbf02b..53790f1 100644 --- a/Data.sln +++ b/Data.sln @@ -17,6 +17,8 @@ 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}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {34BED188-2B88-4CAD-8DD0-6FC70D156902}.Debug|Any CPU.Build.0 = Debug|Any CPU {34BED188-2B88-4CAD-8DD0-6FC70D156902}.Release|Any CPU.ActiveCfg = Release|Any CPU {34BED188-2B88-4CAD-8DD0-6FC70D156902}.Release|Any CPU.Build.0 = Release|Any CPU + {7BB489B2-58C0-4C49-A339-70E4CE750A40}.Debug|Any CPU.ActiveCfg = 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.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PoweredSoft.Data.EntityFramework/ASyncQueryableService.cs b/PoweredSoft.Data.EntityFramework/ASyncQueryableService.cs new file mode 100644 index 0000000..eed8209 --- /dev/null +++ b/PoweredSoft.Data.EntityFramework/ASyncQueryableService.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using PoweredSoft.Data.Core; + +namespace PoweredSoft.Data.EntityFramework +{ + public class AsyncQueryableHandlerService : IAsyncQueryableHandlerService + { + public Task FirstOrDefaultAsync(IQueryable queryable, CancellationToken cancellationToken = default(CancellationToken)) + => queryable.FirstOrDefaultAsync(cancellationToken); + public Task FirstOrDefaultAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default(CancellationToken)) + => queryable.FirstOrDefaultAsync(predicate, cancellationToken); + public Task> ToListAsync(IQueryable queryable, CancellationToken cancellationToken = default(CancellationToken)) + => queryable.ToListAsync(cancellationToken); + public Task CountAsync(IQueryable queryable, CancellationToken cancellationToken = default(CancellationToken)) + => queryable.CountAsync(); + public Task LongCountAsync(IQueryable queryable, CancellationToken cancellationToken = default(CancellationToken)) + => queryable.LongCountAsync(); + + public bool CanHandle(IQueryable queryable) => queryable.Provider is System.Data.Entity.Infrastructure.IDbAsyncQueryProvider; + + public Task AnyAsync(IQueryable queryable, Expression> predicate, CancellationToken cancellationToken = default(CancellationToken)) + => queryable.AnyAsync(predicate, cancellationToken); + + public Task AnyAsync(IQueryable queryable, CancellationToken cancellationToken = default(CancellationToken)) + => queryable.AnyAsync(cancellationToken); + } +} diff --git a/PoweredSoft.Data.EntityFramework/PoweredSoft.Data.EntityFramework.csproj b/PoweredSoft.Data.EntityFramework/PoweredSoft.Data.EntityFramework.csproj new file mode 100644 index 0000000..8e5cc57 --- /dev/null +++ b/PoweredSoft.Data.EntityFramework/PoweredSoft.Data.EntityFramework.csproj @@ -0,0 +1,16 @@ + + + + netstandard2.1;net461 + + + + + + + + + + + + diff --git a/PoweredSoft.Data.EntityFramework/ServiceCollectionExtensions.cs b/PoweredSoft.Data.EntityFramework/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..ff28d68 --- /dev/null +++ b/PoweredSoft.Data.EntityFramework/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.EntityFramework +{ + public static class ServiceCollectionExtensions + { + public static IServiceCollection AddPoweredSoftEntityFrameworkCoreDataServices(this IServiceCollection services) + { + services.AddPoweredSoftDataServices(); + services.AddTransient(); + return services; + } + } +} diff --git a/README.md b/README.md index f12d1f4..c2c00f5 100644 --- a/README.md +++ b/README.md @@ -32,23 +32,9 @@ public class Startup } ``` -> Then somewhere else. - -```csharp -public class SomeClass -{ - private readonly IDbContextFactory contextFactory; - public SomeClass(IDbContextFactoryProvider dbContextFactoryProvider) - { - contextFactory = dbContextFactoryProvider.GetContextFactory(typeof(YourFavoriteContext)); - } -} - -``` - ## AsyncQueryableFactory -Also as the same kind of goal, will slowly add support for a non dependant to orm async method. +Also as the same kind of goal, will slowly add support for a non dependant to orm/drivers async method. ```csharp public interface IAsyncQueryableHandlerService @@ -70,7 +56,7 @@ How to use public class SomeClass { private readonly IAsyncQueryableService asyncQueryableService; - public SomeClass(IDbContextFactoryProvider asyncQueryableService) + public SomeClass(IAsyncQueryableService asyncQueryableService) { this.asyncQueryableService = asyncQueryableService; }