Add project files.
This commit is contained in:
parent
8c151f357f
commit
d755a9a4b8
37
Data.sln
Normal file
37
Data.sln
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.28010.2046
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data.Core", "PoweredSoft.Data.Core\PoweredSoft.Data.Core.csproj", "{6C61F343-9634-40CD-AFC1-7C4C3FB4E524}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data.EntityFrameworkCore", "PoweredSoft.Data.EntityFrameworkCore\PoweredSoft.Data.EntityFrameworkCore.csproj", "{78EEC90C-F2C3-4B59-93DA-DE22BFD1FD30}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{40E6D28E-45E6-418F-BACD-954ED03AC4C8}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
LICENSE.md = LICENSE.md
|
||||||
|
README.md = README.md
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{6C61F343-9634-40CD-AFC1-7C4C3FB4E524}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6C61F343-9634-40CD-AFC1-7C4C3FB4E524}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6C61F343-9634-40CD-AFC1-7C4C3FB4E524}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6C61F343-9634-40CD-AFC1-7C4C3FB4E524}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{78EEC90C-F2C3-4B59-93DA-DE22BFD1FD30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{78EEC90C-F2C3-4B59-93DA-DE22BFD1FD30}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{78EEC90C-F2C3-4B59-93DA-DE22BFD1FD30}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{78EEC90C-F2C3-4B59-93DA-DE22BFD1FD30}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {D3AE5F41-FB7B-4EA8-9C97-1D878E91CE2C}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 Powered Softwares Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
26
PoweredSoft.Data.Core/IDbContextFactory.cs
Normal file
26
PoweredSoft.Data.Core/IDbContextFactory.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PoweredSoft.Data.Core
|
||||||
|
{
|
||||||
|
public interface IDbContextFactory
|
||||||
|
{
|
||||||
|
IQueryable<T> GetQueryable<T>()
|
||||||
|
where T : class;
|
||||||
|
|
||||||
|
IQueryable GetQueryable(Type type);
|
||||||
|
void Add(object entity);
|
||||||
|
void Remove(object entity);
|
||||||
|
int SaveChanges();
|
||||||
|
Task<int> SaveChangesAsync();
|
||||||
|
|
||||||
|
Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken);
|
||||||
|
Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken);
|
||||||
|
Task<List<T>> ToListAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
11
PoweredSoft.Data.Core/IDbContextFactoryProvider.cs
Normal file
11
PoweredSoft.Data.Core/IDbContextFactoryProvider.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PoweredSoft.Data.Core
|
||||||
|
{
|
||||||
|
public interface IDbContextFactoryProvider
|
||||||
|
{
|
||||||
|
IDbContextFactory GetContextFactory(Type contextType);
|
||||||
|
}
|
||||||
|
}
|
16
PoweredSoft.Data.Core/PoweredSoft.Data.Core.csproj
Normal file
16
PoweredSoft.Data.Core/PoweredSoft.Data.Core.csproj
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<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>powered,soft,orm,db,context,ef,ef6,efcore,factory</PackageTags>
|
||||||
|
<Version>1.0.0</Version>
|
||||||
|
<PackageIconUrl>https://secure.gravatar.com/avatar/4e32f73820c16718909a06c2927f1f8b?s=512&amp;r=g&amp;d=retro</PackageIconUrl>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
51
PoweredSoft.Data.EntityFrameworkCore/DbContextFactory.cs
Normal file
51
PoweredSoft.Data.EntityFrameworkCore/DbContextFactory.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PoweredSoft.Data.Core;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PoweredSoft.Data.EntityFrameworkCore
|
||||||
|
{
|
||||||
|
public class DbContextFactory : IDbContextFactory
|
||||||
|
{
|
||||||
|
private readonly DbContext _context;
|
||||||
|
private MethodInfo _setGenericMethod = null;
|
||||||
|
|
||||||
|
public DbContextFactory(DbContext dbContext)
|
||||||
|
{
|
||||||
|
_context = dbContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Add(object entity) => _context.Add(entity);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public IQueryable<T> GetQueryable<T>() where T : class => _context.Set<T>();
|
||||||
|
|
||||||
|
public IQueryable GetQueryable(Type type)
|
||||||
|
{
|
||||||
|
if (_setGenericMethod == null)
|
||||||
|
_setGenericMethod = typeof(DbContextFactory).GetMethods().FirstOrDefault(t => t.Name == nameof(GetQueryable) && t.ContainsGenericParameters);
|
||||||
|
|
||||||
|
var gm = _setGenericMethod.MakeGenericMethod(type);
|
||||||
|
var ret = (IQueryable)gm.Invoke(this, new object[] { });
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(object entity)
|
||||||
|
{
|
||||||
|
_context.Remove(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int SaveChanges() => _context.SaveChanges();
|
||||||
|
public async Task<int> SaveChangesAsync() => await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken)) => queryable.FirstOrDefaultAsync(cancellationToken);
|
||||||
|
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken)) => queryable.FirstOrDefaultAsync(predicate, cancellationToken);
|
||||||
|
public Task<List<T>> ToListAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken)) => queryable.ToListAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
using PoweredSoft.Data.Core;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace PoweredSoft.Data.EntityFrameworkCore
|
||||||
|
{
|
||||||
|
public class DbContextFactoryProvider : IDbContextFactoryProvider
|
||||||
|
{
|
||||||
|
private readonly IServiceProvider serviceProvider;
|
||||||
|
|
||||||
|
public DbContextFactoryProvider(IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
this.serviceProvider = serviceProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDbContextFactory GetContextFactory(Type contextType)
|
||||||
|
{
|
||||||
|
var dbContext = this.serviceProvider.GetRequiredService(contextType) as DbContext;
|
||||||
|
var dbContextFactory = new DbContextFactory(dbContext);
|
||||||
|
return dbContextFactory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.1</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>powered,soft,orm,db,context,ef,ef6,efcore,factory</PackageTags>
|
||||||
|
<Version>1.0.0</Version>
|
||||||
|
<PackageIconUrl>https://secure.gravatar.com/avatar/4e32f73820c16718909a06c2927f1f8b?s=512&amp;r=g&amp;d=retro</PackageIconUrl>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PoweredSoft.Data.Core\PoweredSoft.Data.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using PoweredSoft.Data.Core;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PoweredSoft.Data.EntityFrameworkCore
|
||||||
|
{
|
||||||
|
public static class ServiceCollectionExtensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddPoweredSoftDataServices(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddTransient<IDbContextFactoryProvider, DbContextFactoryProvider>();
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
README.md
Normal file
14
README.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# IDbContextFactory
|
||||||
|
|
||||||
|
The goal of this project is to help, fill the gap of supporting multiple ORM's in DynamicQuery, and possibly more projects in the future.
|
||||||
|
|
||||||
|
One of the most obvious reasy is to be able to execute async/await operations on the context without, the executing library to be dependant on the ORM Framework such as (EF Core, EF6).
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
> Install nuget package to your awesome project.
|
||||||
|
|
||||||
|
Full Version | NuGet | NuGet Install
|
||||||
|
------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------:
|
||||||
|
PoweredSoft.Data.Core | <a href="https://www.nuget.org/packages/PoweredSoft.Data.Core/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.Data.Core.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.Data.Core/)</a> | ```PM> Install-Package PoweredSoft.DynamicQuery```
|
||||||
|
PoweredSoft.Data.EntityFrameworkCore | <a href="https://www.nuget.org/packages/PoweredSoft.Data.EntityFrameworkCore/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.Data.EntityFrameworkCore.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.Data.EntityFrameworkCore/)</a> | ```PM> Install-Package PoweredSoft.Data.EntityFrameworkCore```
|
Loading…
Reference in New Issue
Block a user