Browse Source

Refactorings.

pull/81/head
Halil İbrahim Kalkan 10 years ago
parent
commit
95eeb92303
  1. 2
      src/Volo.Abp.ApplicationContracts/Volo/Abp/Application/Services/Dtos/EntityDto.cs
  2. 22
      src/Volo.Abp.ApplicationContracts/Volo/Abp/Application/Services/Dtos/IEntityDto.cs
  3. 2
      src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs
  4. 1
      src/Volo.Abp/Volo/Abp/Domain/Entities/AggregateRoot.cs
  5. 13
      src/Volo.Abp/Volo/Abp/Domain/Entities/Entity.cs
  6. 5
      src/Volo.Abp/Volo/Abp/Domain/Entities/EntityHelper.cs
  7. 2
      src/Volo.Abp/Volo/Abp/Domain/Entities/EntityNotFoundException.cs
  8. 5
      src/Volo.Abp/Volo/Abp/Domain/Repositories/IQueryableRepository.cs
  9. 27
      src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepository.cs

2
src/Volo.Abp.ApplicationContracts/Volo/Abp/Application/Services/Dtos/EntityDto.cs

@ -6,7 +6,7 @@ namespace Volo.Abp.Application.Services.Dtos
/// Implements common properties for entity based DTOs. /// Implements common properties for entity based DTOs.
/// </summary> /// </summary>
/// <typeparam name="TPrimaryKey">Type of the primary key</typeparam> /// <typeparam name="TPrimaryKey">Type of the primary key</typeparam>
public class EntityDto<TPrimaryKey> public class EntityDto<TPrimaryKey> : IEntityDto<TPrimaryKey>
{ {
/// <summary> /// <summary>
/// Id of the entity. /// Id of the entity.

22
src/Volo.Abp.ApplicationContracts/Volo/Abp/Application/Services/Dtos/IEntityDto.cs

@ -0,0 +1,22 @@
namespace Volo.Abp.Application.Services.Dtos
{
///// <summary>
///// A shortcut of <see cref="IEntityDto{TPrimaryKey}"/> for most used primary key type (<see cref="int"/>).
///// </summary>
//public interface IEntityDto : IEntityDto<int>
//{
//}
/// <summary>
/// Defines common properties for entity based DTOs.
/// </summary>
/// <typeparam name="TPrimaryKey"></typeparam>
public interface IEntityDto<TPrimaryKey>
{
/// <summary>
/// Id of the entity.
/// </summary>
TPrimaryKey Id { get; set; }
}
}

2
src/Volo.Abp.EntityFrameworkCore/Microsoft/Extensions/DependencyInjection/AbpEfCoreServiceCollectionExtensions.cs

@ -25,7 +25,7 @@ namespace Microsoft.Extensions.DependencyInjection
services.TryAddTransient<TDbContext>(); services.TryAddTransient<TDbContext>();
services.TryAddSingleton(serviceProvider => services.TryAddSingleton(serviceProvider =>
{ {
const string moduleName = ""; const string moduleName = ""; //TODO: Use AbpModuleDescriptor instead of module name?
var connInfoResolver = serviceProvider.GetRequiredService<IConnectionStringResolver>(); var connInfoResolver = serviceProvider.GetRequiredService<IConnectionStringResolver>();

1
src/Volo.Abp/Volo/Abp/Domain/Entities/AggregateRoot.cs

@ -2,5 +2,6 @@
{ {
public class AggregateRoot<TPrimaryKey> : Entity<TPrimaryKey>, IAggregateRoot<TPrimaryKey> public class AggregateRoot<TPrimaryKey> : Entity<TPrimaryKey>, IAggregateRoot<TPrimaryKey>
{ {
} }
} }

13
src/Volo.Abp/Volo/Abp/Domain/Entities/Entity.cs

@ -79,19 +79,6 @@ namespace Volo.Abp.Domain.Entities
return false; return false;
} }
//TODO: How to handle this?
//if (this is IMayHaveTenant && other is IMayHaveTenant &&
// this.As<IMayHaveTenant>().TenantId != other.As<IMayHaveTenant>().TenantId)
//{
// return false;
//}
//if (this is IMustHaveTenant && other is IMustHaveTenant &&
// this.As<IMustHaveTenant>().TenantId != other.As<IMustHaveTenant>().TenantId)
//{
// return false;
//}
return Id.Equals(other.Id); return Id.Equals(other.Id);
} }

5
src/Volo.Abp/Volo/Abp/Domain/Entities/EntityHelper.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Reflection; using System.Reflection;
using JetBrains.Annotations;
using Volo.Abp.Reflection; using Volo.Abp.Reflection;
namespace Volo.Abp.Domain.Entities namespace Volo.Abp.Domain.Entities
@ -9,7 +10,7 @@ namespace Volo.Abp.Domain.Entities
/// </summary> /// </summary>
public static class EntityHelper public static class EntityHelper
{ {
public static bool IsEntity(Type type) public static bool IsEntity([NotNull] Type type)
{ {
return ReflectionHelper.IsAssignableToGenericType(type, typeof (IEntity<>)); return ReflectionHelper.IsAssignableToGenericType(type, typeof (IEntity<>));
} }
@ -22,7 +23,7 @@ namespace Volo.Abp.Domain.Entities
/// <summary> /// <summary>
/// Gets primary key type of given entity type /// Gets primary key type of given entity type
/// </summary> /// </summary>
public static Type GetPrimaryKeyType(Type entityType) public static Type GetPrimaryKeyType([NotNull] Type entityType)
{ {
foreach (var interfaceType in entityType.GetTypeInfo().GetInterfaces()) foreach (var interfaceType in entityType.GetTypeInfo().GetInterfaces())
{ {

2
src/Volo.Abp/Volo/Abp/Domain/Entities/EntityNotFoundException.cs

@ -5,7 +5,7 @@ namespace Volo.Abp.Domain.Entities
/// <summary> /// <summary>
/// This exception is thrown if an entity excepted to be found but not found. /// This exception is thrown if an entity excepted to be found but not found.
/// </summary> /// </summary>
//[Serializable] //TODO: [Serializable]
public class EntityNotFoundException : AbpException public class EntityNotFoundException : AbpException
{ {
/// <summary> /// <summary>

5
src/Volo.Abp/Volo/Abp/Domain/Repositories/IQueryableRepository.cs

@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Domain.Repositories namespace Volo.Abp.Domain.Repositories
@ -16,7 +17,7 @@ namespace Volo.Abp.Domain.Repositories
/// given predicate. /// given predicate.
/// </summary> /// </summary>
/// <param name="predicate">A condition to filter entities</param> /// <param name="predicate">A condition to filter entities</param>
void Delete(Expression<Func<TEntity, bool>> predicate); void Delete([NotNull] Expression<Func<TEntity, bool>> predicate);
/// <summary> /// <summary>
/// Deletes many entities by function. /// Deletes many entities by function.
@ -25,6 +26,6 @@ namespace Volo.Abp.Domain.Repositories
/// given predicate. /// given predicate.
/// </summary> /// </summary>
/// <param name="predicate">A condition to filter entities</param> /// <param name="predicate">A condition to filter entities</param>
Task DeleteAsync(Expression<Func<TEntity, bool>> predicate); Task DeleteAsync([NotNull] Expression<Func<TEntity, bool>> predicate);
} }
} }

27
src/Volo.Abp/Volo/Abp/Domain/Repositories/IRepository.cs

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.DependencyInjection; using Volo.DependencyInjection;
@ -17,12 +18,14 @@ namespace Volo.Abp.Domain.Repositories
/// Used to get all entities. /// Used to get all entities.
/// </summary> /// </summary>
/// <returns>List of all entities</returns> /// <returns>List of all entities</returns>
[NotNull]
List<TEntity> GetList(); List<TEntity> GetList();
/// <summary> /// <summary>
/// Used to get all entities. /// Used to get all entities.
/// </summary> /// </summary>
/// <returns>List of all entities</returns> /// <returns>List of all entities</returns>
[NotNull]
Task<List<TEntity>> GetListAsync(); Task<List<TEntity>> GetListAsync();
/// <summary> /// <summary>
@ -30,6 +33,7 @@ namespace Volo.Abp.Domain.Repositories
/// </summary> /// </summary>
/// <param name="id">Primary key of the entity to get</param> /// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity</returns> /// <returns>Entity</returns>
[NotNull]
TEntity Get(TPrimaryKey id); TEntity Get(TPrimaryKey id);
/// <summary> /// <summary>
@ -37,6 +41,7 @@ namespace Volo.Abp.Domain.Repositories
/// </summary> /// </summary>
/// <param name="id">Primary key of the entity to get</param> /// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity</returns> /// <returns>Entity</returns>
[NotNull]
Task<TEntity> GetAsync(TPrimaryKey id); Task<TEntity> GetAsync(TPrimaryKey id);
/// <summary> /// <summary>
@ -44,6 +49,7 @@ namespace Volo.Abp.Domain.Repositories
/// </summary> /// </summary>
/// <param name="id">Primary key of the entity to get</param> /// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity or null</returns> /// <returns>Entity or null</returns>
[CanBeNull]
TEntity Find(TPrimaryKey id); TEntity Find(TPrimaryKey id);
/// <summary> /// <summary>
@ -51,19 +57,22 @@ namespace Volo.Abp.Domain.Repositories
/// </summary> /// </summary>
/// <param name="id">Primary key of the entity to get</param> /// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity or null</returns> /// <returns>Entity or null</returns>
[CanBeNull]
Task<TEntity> FindAsync(TPrimaryKey id); Task<TEntity> FindAsync(TPrimaryKey id);
/// <summary> /// <summary>
/// Inserts a new entity. /// Inserts a new entity.
/// </summary> /// </summary>
/// <param name="entity">Inserted entity</param> /// <param name="entity">Inserted entity</param>
TEntity Insert(TEntity entity); [NotNull]
TEntity Insert([NotNull] TEntity entity);
/// <summary> /// <summary>
/// Inserts a new entity. /// Inserts a new entity.
/// </summary> /// </summary>
/// <param name="entity">Inserted entity</param> /// <param name="entity">Inserted entity</param>
Task<TEntity> InsertAsync(TEntity entity); [NotNull]
Task<TEntity> InsertAsync([NotNull] TEntity entity);
/// <summary> /// <summary>
/// Inserts a new entity and gets it's Id. /// Inserts a new entity and gets it's Id.
@ -72,7 +81,7 @@ namespace Volo.Abp.Domain.Repositories
/// </summary> /// </summary>
/// <param name="entity">Entity</param> /// <param name="entity">Entity</param>
/// <returns>Id of the entity</returns> /// <returns>Id of the entity</returns>
TPrimaryKey InsertAndGetId(TEntity entity); TPrimaryKey InsertAndGetId([NotNull] TEntity entity);
/// <summary> /// <summary>
/// Inserts a new entity and gets it's Id. /// Inserts a new entity and gets it's Id.
@ -81,31 +90,33 @@ namespace Volo.Abp.Domain.Repositories
/// </summary> /// </summary>
/// <param name="entity">Entity</param> /// <param name="entity">Entity</param>
/// <returns>Id of the entity</returns> /// <returns>Id of the entity</returns>
Task<TPrimaryKey> InsertAndGetIdAsync(TEntity entity); Task<TPrimaryKey> InsertAndGetIdAsync([NotNull] TEntity entity);
/// <summary> /// <summary>
/// Updates an existing entity. /// Updates an existing entity.
/// </summary> /// </summary>
/// <param name="entity">Entity</param> /// <param name="entity">Entity</param>
TEntity Update(TEntity entity); [NotNull]
TEntity Update([NotNull] TEntity entity);
/// <summary> /// <summary>
/// Updates an existing entity. /// Updates an existing entity.
/// </summary> /// </summary>
/// <param name="entity">Entity</param> /// <param name="entity">Entity</param>
Task<TEntity> UpdateAsync(TEntity entity); [NotNull]
Task<TEntity> UpdateAsync([NotNull] TEntity entity);
/// <summary> /// <summary>
/// Deletes an entity. /// Deletes an entity.
/// </summary> /// </summary>
/// <param name="entity">Entity to be deleted</param> /// <param name="entity">Entity to be deleted</param>
void Delete(TEntity entity); void Delete([NotNull] TEntity entity);
/// <summary> /// <summary>
/// Deletes an entity. /// Deletes an entity.
/// </summary> /// </summary>
/// <param name="entity">Entity to be deleted</param> /// <param name="entity">Entity to be deleted</param>
Task DeleteAsync(TEntity entity); Task DeleteAsync([NotNull] TEntity entity);
/// <summary> /// <summary>
/// Deletes an entity by primary key. /// Deletes an entity by primary key.

Loading…
Cancel
Save