Browse Source

Created IReadOnlyBasicRepository{TEntity} interface.

pull/301/head
Halil İbrahim Kalkan 8 years ago
parent
commit
4b4531366d
  1. 35
      src/Volo.Abp.Ddd.Domain/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs
  2. 8
      src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs
  3. 2
      src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IBasicRepository.cs
  4. 37
      src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyBasicRepository.cs
  5. 3
      src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyRepository.cs
  6. 24
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs
  7. 5
      src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs
  8. 10
      src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs
  9. 5
      test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs

35
src/Volo.Abp.Ddd.Domain/Microsoft/Extensions/DependencyInjection/ServiceCollectionRepositoryExtensions.cs

@ -9,24 +9,31 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static IServiceCollection AddDefaultRepository(this IServiceCollection services, Type entityType, Type repositoryImplementationType)
{
//IReadOnlyRepository<TEntity>
var readOnlyRepositoryInterface = typeof(IReadOnlyRepository<>).MakeGenericType(entityType);
if (readOnlyRepositoryInterface.IsAssignableFrom(repositoryImplementationType))
//IReadOnlyBasicRepository<TEntity>
var readOnlyBasicRepositoryInterface = typeof(IReadOnlyBasicRepository<>).MakeGenericType(entityType);
if (readOnlyBasicRepositoryInterface.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(readOnlyRepositoryInterface, repositoryImplementationType);
}
services.TryAddTransient(readOnlyBasicRepositoryInterface, repositoryImplementationType);
//IBasicRepository<TEntity>
var basicRepositoryInterface = typeof(IBasicRepository<>).MakeGenericType(entityType);
if (basicRepositoryInterface.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(basicRepositoryInterface, repositoryImplementationType);
//IReadOnlyRepository<TEntity>
var readOnlyRepositoryInterface = typeof(IReadOnlyRepository<>).MakeGenericType(entityType);
if (readOnlyRepositoryInterface.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(readOnlyRepositoryInterface, repositoryImplementationType);
}
//IRepository<TEntity>
var repositoryInterface = typeof(IRepository<>).MakeGenericType(entityType);
if (repositoryInterface.IsAssignableFrom(repositoryImplementationType))
//IBasicRepository<TEntity>
var basicRepositoryInterface = typeof(IBasicRepository<>).MakeGenericType(entityType);
if (basicRepositoryInterface.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(repositoryInterface, repositoryImplementationType);
services.TryAddTransient(basicRepositoryInterface, repositoryImplementationType);
//IRepository<TEntity>
var repositoryInterface = typeof(IRepository<>).MakeGenericType(entityType);
if (repositoryInterface.IsAssignableFrom(repositoryImplementationType))
{
services.TryAddTransient(repositoryInterface, repositoryImplementationType);
}
}
}

8
src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
@ -45,6 +46,13 @@ namespace Volo.Abp.Domain.Repositories
{
return CancellationTokenProvider.FallbackToProvider(prefferedValue);
}
public abstract List<TEntity> GetList(bool includeDetails = false);
public virtual Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{
return Task.FromResult(GetList(includeDetails));
}
}
public abstract class BasicRepositoryBase<TEntity, TKey> : BasicRepositoryBase<TEntity>, IBasicRepository<TEntity, TKey>

2
src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IBasicRepository.cs

@ -5,7 +5,7 @@ using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Domain.Repositories
{
public interface IBasicRepository<TEntity> : IRepository
public interface IBasicRepository<TEntity> : IReadOnlyBasicRepository<TEntity>
where TEntity : class, IEntity
{
/// <summary>

37
src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyBasicRepository.cs

@ -6,7 +6,26 @@ using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Domain.Repositories
{
public interface IReadOnlyBasicRepository<TEntity, TKey> : IRepository
public interface IReadOnlyBasicRepository<TEntity> : IRepository
where TEntity : class, IEntity
{
/// <summary>
/// Gets a list of all the entities.
/// </summary>
/// <param name="includeDetails">Set true to include all children of this entity</param>
/// <returns>Entity</returns>
List<TEntity> GetList(bool includeDetails = false);
/// <summary>
/// Gets a list of all the entities.
/// </summary>
/// <param name="includeDetails">Set true to include all children of this entity</param>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>Entity</returns>
Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default);
}
public interface IReadOnlyBasicRepository<TEntity, TKey> : IReadOnlyBasicRepository<TEntity>
where TEntity : class, IEntity<TKey>
{
/// <summary>
@ -30,22 +49,6 @@ namespace Volo.Abp.Domain.Repositories
[NotNull]
Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default);
///// <summary>
///// Gets a list containing all the entities.
///// </summary>
///// <param name="includeDetails">Set true to include all children of this entity</param>
///// <returns>Entity</returns>
//[NotNull]
//List<TEntity> GetList(bool includeDetails = true);
///// <summary>
///// Gets a list containing all the entities.
///// </summary>
///// <param name="includeDetails">Set true to include all children of this entity</param>
///// <returns>Entity</returns>
//[NotNull]
//Task<List<TEntity>> GetListAsync(bool includeDetails = true);
/// <summary>
/// Gets an entity with given primary key or null if not found.
/// </summary>

3
src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyRepository.cs

@ -5,7 +5,8 @@ using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Domain.Repositories
{
public interface IReadOnlyRepository<TEntity> : IQueryable<TEntity>
public interface IReadOnlyRepository<TEntity> : IQueryable<TEntity>, IReadOnlyBasicRepository<TEntity>
where TEntity : class, IEntity
{
IQueryable<TEntity> WithDetails();

24
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs

@ -112,6 +112,20 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
}
}
public override List<TEntity> GetList(bool includeDetails = false)
{
return includeDetails
? WithDetails().ToList()
: DbSet.ToList();
}
public override Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{
return includeDetails
? WithDetails().ToListAsync(cancellationToken)
: DbSet.ToListAsync(cancellationToken);
}
protected override IQueryable<TEntity> GetQueryable()
{
return DbSet.AsQueryable();
@ -222,16 +236,6 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
return entity;
}
//public List<TEntity> GetList(bool includeDetails = true)
//{
// throw new NotImplementedException();
//}
//public Task<List<TEntity>> GetListAsync(bool includeDetails = true)
//{
// throw new NotImplementedException();
//}
public virtual TEntity Find(TKey id, bool includeDetails = true)
{
return includeDetails

5
src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs

@ -41,6 +41,11 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb
Collection.Remove(entity);
}
public override List<TEntity> GetList(bool includeDetails = false)
{
return Collection.ToList();
}
protected override IQueryable<TEntity> GetQueryable()
{
return ApplyDataFilters(Collection.AsQueryable());

10
src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

@ -173,6 +173,16 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
}
}
public override List<TEntity> GetList(bool includeDetails = false)
{
return GetMongoQueryable().ToList();
}
public override async Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().ToListAsync(cancellationToken);
}
public override void Delete(Expression<Func<TEntity, bool>> predicate, bool autoSave = false)
{
var entities = GetMongoQueryable()

5
test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs

@ -250,6 +250,11 @@ namespace Volo.Abp.Domain.Repositories
throw new NotImplementedException();
}
public override List<TEntity> GetList(bool includeDetails = false)
{
throw new NotImplementedException();
}
protected override IQueryable<TEntity> GetQueryable()
{
throw new NotImplementedException();

Loading…
Cancel
Save