Browse Source

Revised IEfCoreRepository interface.

pull/81/head
Halil İbrahim Kalkan 10 years ago
parent
commit
f393a79699
  1. 16
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs
  2. 6
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs
  3. 10
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs
  4. 2
      src/Volo.DependencyInjection/Volo/DependencyInjection/ExposeServicesAttribute.cs

16
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs

@ -11,17 +11,17 @@ namespace Volo.Abp.Repositories
public static DbContext GetDbContext<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository) public static DbContext GetDbContext<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository)
where TEntity : class, IEntity<TPrimaryKey>, new() where TEntity : class, IEntity<TPrimaryKey>, new()
{ {
var efCoreRepository = repository as IEfCoreRepository; return repository.ToEfCoreRepository().DbContext;
if (efCoreRepository == null)
{
throw new ArgumentException("Given repository does not implement " + typeof(IEfCoreRepository).AssemblyQualifiedName, nameof(repository));
}
return efCoreRepository.DbContext;
} }
public static DbSet<TEntity> GetDbSet<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository) public static DbSet<TEntity> GetDbSet<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository)
where TEntity : class, IEntity<TPrimaryKey>, new() where TEntity : class, IEntity<TPrimaryKey>, new()
{
return repository.ToEfCoreRepository().DbSet;
}
public static IEfCoreRepository<TEntity, TPrimaryKey> ToEfCoreRepository<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository)
where TEntity : class, IEntity<TPrimaryKey>, new()
{ {
var efCoreRepository = repository as IEfCoreRepository<TEntity, TPrimaryKey>; var efCoreRepository = repository as IEfCoreRepository<TEntity, TPrimaryKey>;
if (efCoreRepository == null) if (efCoreRepository == null)
@ -29,7 +29,7 @@ namespace Volo.Abp.Repositories
throw new ArgumentException("Given repository does not implement " + typeof(IEfCoreRepository<TEntity, TPrimaryKey>).AssemblyQualifiedName, nameof(repository)); throw new ArgumentException("Given repository does not implement " + typeof(IEfCoreRepository<TEntity, TPrimaryKey>).AssemblyQualifiedName, nameof(repository));
} }
return efCoreRepository.DbSet; return efCoreRepository;
} }
} }
} }

6
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs

@ -12,11 +12,11 @@ namespace Volo.Abp.Repositories.EntityFrameworkCore
where TDbContext : AbpDbContext<TDbContext> where TDbContext : AbpDbContext<TDbContext>
where TEntity : class, IEntity<TPrimaryKey> where TEntity : class, IEntity<TPrimaryKey>
{ {
public virtual TDbContext DbContext => _dbContextProvider.GetDbContext();
public virtual DbSet<TEntity> DbSet => DbContext.Set<TEntity>(); public virtual DbSet<TEntity> DbSet => DbContext.Set<TEntity>();
DbContext IEfCoreRepository.DbContext => DbContext; DbContext IEfCoreRepository<TEntity, TPrimaryKey>.DbContext => DbContext;
protected virtual TDbContext DbContext => _dbContextProvider.GetDbContext();
private readonly IDbContextProvider<TDbContext> _dbContextProvider; private readonly IDbContextProvider<TDbContext> _dbContextProvider;

10
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs

@ -1,16 +1,14 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.Repositories.EntityFrameworkCore namespace Volo.Abp.Repositories.EntityFrameworkCore
{ {
public interface IEfCoreRepository public interface IEfCoreRepository<TEntity, TPrimaryKey> : IQueryableRepository<TEntity, TPrimaryKey>
{
DbContext DbContext { get; }
}
public interface IEfCoreRepository<TEntity, TPrimaryKey> : IEfCoreRepository
where TEntity : class, IEntity<TPrimaryKey> where TEntity : class, IEntity<TPrimaryKey>
{ {
DbContext DbContext { get; }
DbSet<TEntity> DbSet { get; } DbSet<TEntity> DbSet { get; }
} }
} }

2
src/Volo.DependencyInjection/Volo/DependencyInjection/ExposeServicesAttribute.cs

@ -8,7 +8,7 @@ namespace Volo.DependencyInjection
public ExposeServicesAttribute(params Type[] exposedServiceTypes) public ExposeServicesAttribute(params Type[] exposedServiceTypes)
{ {
ExposedServiceTypes = exposedServiceTypes ?? new Type[]; ExposedServiceTypes = exposedServiceTypes ?? new Type[0];
} }
public Type[] GetExposedServiceTypes() public Type[] GetExposedServiceTypes()

Loading…
Cancel
Save