全流程跑通啦~~框架完成基本功能增删改查

This commit is contained in:
橙子
2023-01-15 17:32:27 +08:00
parent f1e314fa13
commit 1314cf1c19
25 changed files with 296 additions and 80 deletions

View File

@@ -1,14 +1,16 @@
using AutoMapper;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Model;
namespace Yi.Framework.Ddd.Services
{
public abstract class ApplicationService
{
public IMapper _mapper { get; set; }
public IMapper _mapper { get => ServiceLocatorModel.Instance.GetRequiredService<IMapper>(); }
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Helper;
using Yi.Framework.Ddd.Dtos;
using Yi.Framework.Ddd.Entities;
using Yi.Framework.Ddd.Services.Abstract;
@@ -62,11 +63,15 @@ namespace Yi.Framework.Ddd.Services
//这里判断实体的T给id赋值
//雪花id
//if (entity is IEntity<long>)
//{
// //使用反射暂时先使用sqlsuga的雪花id提供
// entityWithLongId.Id = SqlSugar.SnowFlakeSingle.Instance.NextId();
//}
if (entity is IEntity<long> entityForlongId)
{
if (entityForlongId.Id is default(long))
{
//使用反射暂时先使用sqlsuga的雪花id提供
//ps: linshi
ReflexHelper.SetModelValue("Id", SnowflakeHelper.NextId, entity);
}
}
return Task.FromResult(entity);
@@ -86,6 +91,7 @@ namespace Yi.Framework.Ddd.Services
{
var entity = await MapToEntityAsync(input);
//这里还可以设置租户
await _repository.InsertAsync(entity);
return await MapToGetOutputDtoAsync(entity);

View File

@@ -1,8 +1,10 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Model;
using Yi.Framework.Ddd.Dtos;
using Yi.Framework.Ddd.Entities;
using Yi.Framework.Ddd.Repositories;
@@ -30,7 +32,10 @@ where TEntityDto : IEntityDto<TKey>
IReadOnlyAppService<TGetOutputDto, TGetListOutputDto, TKey, TGetListInput>
where TEntity : class, IEntity
{
protected IRepository<TEntity> _repository { get; }
/// <summary>
/// 先暂时用服务定位的方式,之后将更改为属性注入
/// </summary>
protected IRepository<TEntity> _repository { get => ServiceLocatorModel.Instance.GetRequiredService<IRepository<TEntity>>(); }
//Mapper
protected virtual Task<TGetOutputDto> MapToGetOutputDtoAsync(TEntity entity)

View File

@@ -28,6 +28,11 @@
<returns></returns>
<exception cref="T:System.ArgumentNullException"></exception>
</member>
<member name="P:Yi.Framework.Ddd.Services.ReadOnlyAppService`5._repository">
<summary>
先暂时用服务定位的方式,之后将更改为属性注入
</summary>
</member>
<member name="M:Yi.Framework.Ddd.Services.ReadOnlyAppService`5.GetAsync(`3)">
<summary>
单查