初始提交

This commit is contained in:
wanyongkang
2020-10-07 20:25:03 +08:00
commit d318014316
3809 changed files with 263103 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
namespace Hncore.Infrastructure.DDD
{
public abstract class AggregateRoot<TId> : Entity<TId>, IAggregateRoot<TId>
{
public AggregateRoot()
{
}
}
}

View File

@@ -0,0 +1,48 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Hncore.Infrastructure.DDD
{
/// <summary>
/// 实现模型抽象基类
/// </summary>
/// <typeparam name="TId">主键数据类型</typeparam>
public abstract class Entity<TId> : IEntity<TId>
{
/// <summary>
/// 记录数据库主键ID
/// </summary>
[JsonProperty("Id")]
public virtual TId Id { get; set; }
}
public abstract class EntityWithTime<TId> : Entity<TId>
{
/// <summary>
/// 记录添加(创建)时间
/// </summary>
public virtual DateTime CreateTime { get; set; } = DateTime.Now;
/// <summary>
/// 记录最后更新时间
/// </summary>
public virtual DateTime UpdateTime { get; set; } = DateTime.Now;
/// <summary>
/// 记录软删除标记0.代表正常1.代表已删除
/// </summary>
public virtual int DeleteTag { get; set; }
}
public abstract class EntityWithDelete<TId> : Entity<TId>,ISoftDelete
{
/// <summary>
/// 记录软删除标记0.代表正常1.代表已删除
/// </summary>
public virtual int DeleteTag { get; set; } = 0;
}
}

View File

@@ -0,0 +1,6 @@
namespace Hncore.Infrastructure.DDD
{
public interface IAggregateRoot<TId> : IEntity<TId>
{
}
}

View File

@@ -0,0 +1,16 @@
using System;
namespace Hncore.Infrastructure.DDD
{
public interface IEntity
{
}
public interface IEntity<TId>: IEntity
{
TId Id
{
get;
}
}
}

View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Hncore.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace Hncore.Infrastructure.DDD
{
public interface IQuery<TEntity,TId> where TEntity : IEntity<TId>
{
TEntity GetOne(Expression<Func<TEntity, bool>> condition);
Task<TEntity> GetOneAsync(Expression<Func<TEntity, bool>> condition);
PageData<TEntity> GetList(Expression<Func<TEntity, bool>> condition, int pagesize, int pageindex, bool istotal);
Task<PageData<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> condition, int pagesize, int pageindex, bool istotal);
List<TEntity> GetList(Expression<Func<TEntity, bool>> condition);
Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> condition);
bool Exists(Expression<Func<TEntity, bool>> condition);
Task<bool> ExistsAsync(Expression<Func<TEntity, bool>> condition);
List<TEntity> TopN(Expression<Func<TEntity, bool>> condition, int topN);
Task<List<TEntity>> TopNAsync(Expression<Func<TEntity, bool>> condition, int topN);
IQueryable<TEntity> GetListQueryable(Expression<Func<TEntity, bool>> condition);
IQueryable<TEntity> GetQueryable();
DbContext DbContext();
}
}

View File

@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Infrastructure.DDD
{
public interface IRepository<TEntity, TId> where TEntity : IEntity<TId>
{
TEntity FindById(TId id);
Task<TEntity> FindByIdAsync(TId id);
void Add(TEntity entity);
Task AddAsync(TEntity entity);
/// <summary>
/// 批量添加
/// </summary>
/// <param name="entity"></param>
void AddRange(List<TEntity> entity);
/// <summary>
/// 批量添加
/// </summary>
/// <param name="entity"></param>
Task AddRangeAsync(List<TEntity> entity);
/// <summary>
/// 批量修改
/// </summary>
/// <param name="entity"></param>
void UpdateRange(List<TEntity> entity);
/// <summary>
/// 批量删除
/// </summary>
/// <param name="entity"></param>
void RemoveRange(List<TEntity> entity);
void Remove(TEntity entity);
void Update(TEntity entity);
IQueryable<TEntity> GetQueryable();
}
}

View File

@@ -0,0 +1,7 @@
namespace Hncore.Infrastructure.DDD
{
public interface ISoftDelete
{
int DeleteTag { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Hncore.Infrastructure.DDD
{
public interface ITenant
{
int TenantId { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace Hncore.Infrastructure.DDD
{
public interface ITenantStore
{
int StoreId { get; set; }
}
}