Introduced readonly repositories.

pull/272/head
Halil İbrahim Kalkan 7 years ago
parent e40e1062e6
commit 453fd88d1b

@ -76,44 +76,9 @@ namespace Volo.Abp.Domain.Repositories
Task DeleteAsync([NotNull] TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); //TODO: Return true if deleted
}
public interface IBasicRepository<TEntity, TKey> : IBasicRepository<TEntity>
public interface IBasicRepository<TEntity, TKey> : IBasicRepository<TEntity>, IReadOnlyBasicRepository<TEntity, TKey>
where TEntity : class, IEntity<TKey>
{
/// <summary>
/// Gets an entity with given primary key.
/// Throws <see cref="EntityNotFoundException"/> if can not find an entity with given id.
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity</returns>
[NotNull]
TEntity Get(TKey id);
/// <summary>
/// Gets an entity with given primary key.
/// Throws <see cref="EntityNotFoundException"/> if can not find an entity with given id.
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>Entity</returns>
[NotNull]
Task<TEntity> GetAsync(TKey id, CancellationToken cancellationToken = default);
/// <summary>
/// Gets an entity with given primary key or null if not found.
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity or null</returns>
[CanBeNull]
TEntity Find(TKey id);
/// <summary>
/// Gets an entity with given primary key or null if not found.
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>Entity or null</returns>
Task<TEntity> FindAsync(TKey id, CancellationToken cancellationToken = default);
/// <summary>
/// Deletes an entity by primary key.
/// </summary>

@ -0,0 +1,46 @@
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Domain.Repositories
{
public interface IReadOnlyBasicRepository<TEntity, TKey> : IRepository
where TEntity : class, IEntity<TKey>
{
/// <summary>
/// Gets an entity with given primary key.
/// Throws <see cref="EntityNotFoundException"/> if can not find an entity with given id.
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity</returns>
[NotNull]
TEntity Get(TKey id);
/// <summary>
/// Gets an entity with given primary key.
/// Throws <see cref="EntityNotFoundException"/> if can not find an entity with given id.
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>Entity</returns>
[NotNull]
Task<TEntity> GetAsync(TKey id, CancellationToken cancellationToken = default);
/// <summary>
/// Gets an entity with given primary key or null if not found.
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity or null</returns>
[CanBeNull]
TEntity Find(TKey id);
/// <summary>
/// Gets an entity with given primary key or null if not found.
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>Entity or null</returns>
Task<TEntity> FindAsync(TKey id, CancellationToken cancellationToken = default);
}
}

@ -0,0 +1,16 @@
using System.Linq;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Domain.Repositories
{
public interface IReadOnlyRepository<TEntity> : IQueryable<TEntity>
{
}
public interface IReadOnlyRepository<TEntity, TKey> : IReadOnlyRepository<TEntity>, IReadOnlyBasicRepository<TEntity, TKey>
where TEntity : class, IEntity<TKey>
{
}
}

@ -13,12 +13,12 @@ namespace Volo.Abp.Domain.Repositories
/// <summary>
/// Just to mark a class as repository.
/// </summary>
public interface IRepository : ITransientDependency, IUnitOfWorkEnabled
public interface IRepository : IUnitOfWorkEnabled, ITransientDependency
{
}
public interface IRepository<TEntity> : IBasicRepository<TEntity>, IQueryable<TEntity>
public interface IRepository<TEntity> : IReadOnlyRepository<TEntity>, IBasicRepository<TEntity>
where TEntity : class, IEntity
{
/// <summary>
@ -49,7 +49,7 @@ namespace Volo.Abp.Domain.Repositories
Task DeleteAsync([NotNull] Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default);
}
public interface IRepository<TEntity, TKey> : IRepository<TEntity>, IBasicRepository<TEntity, TKey>
public interface IRepository<TEntity, TKey> : IRepository<TEntity>, IReadOnlyRepository<TEntity, TKey>, IBasicRepository<TEntity, TKey>
where TEntity : class, IEntity<TKey>
{
}

Loading…
Cancel
Save