feat: 完善种子数据功能
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Yi.Framework.Core.Attributes
|
||||
/// 1、[AppService]:自动去找接口,如果存在就是接口,如果不存在就是本身
|
||||
/// 2、[AppService(ServiceType = typeof(注册抽象或者接口或者本身))],手动去注册,放type即可
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
|
||||
public class AppServiceAttribute : Attribute
|
||||
{
|
||||
public AppServiceAttribute() { }
|
||||
|
||||
@@ -46,7 +46,15 @@ namespace Yi.Framework.Core.Extensions
|
||||
|
||||
private static void RegIocByAttribute(IServiceCollection services, Type type)
|
||||
{
|
||||
var serviceAttribute = type.GetCustomAttribute<AppServiceAttribute>();
|
||||
var serviceAttributes = type.GetCustomAttributes<AppServiceAttribute>();
|
||||
if (serviceAttributes is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//处理多个特性注入情况
|
||||
foreach (var serviceAttribute in serviceAttributes)
|
||||
{
|
||||
|
||||
if (serviceAttribute is not null)
|
||||
{
|
||||
//泛型类需要单独进行处理
|
||||
@@ -82,6 +90,9 @@ namespace Yi.Framework.Core.Extensions
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void RegIocByInterface(IServiceCollection services, Type type)
|
||||
|
||||
@@ -7,7 +7,7 @@ using Yi.Framework.Ddd.Repositories;
|
||||
|
||||
namespace Yi.Framework.Data.DataSeeds
|
||||
{
|
||||
public abstract class AbstractDataSeed<TEntity> : IDataSeed
|
||||
public abstract class AbstractDataSeed<TEntity> : IDataSeed<TEntity>
|
||||
{
|
||||
private readonly IRepository<TEntity> _repository;
|
||||
public AbstractDataSeed(IRepository<TEntity> repository)
|
||||
|
||||
@@ -10,4 +10,8 @@ namespace Yi.Framework.Data.DataSeeds
|
||||
{
|
||||
Task<bool> InvokerAsync();
|
||||
}
|
||||
|
||||
public interface IDataSeed<TEntity>: IDataSeed
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ using Yi.Framework.Ddd.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Yi.BBS.Application.Contracts.GlobalSetting.Dtos.Temp;
|
||||
using Yi.BBS.Domain.Shared;
|
||||
using Yi.Framework.Data.DataSeeds;
|
||||
using Yi.RBAC.Domain.Identity.Entities;
|
||||
|
||||
namespace Yi.BBS.Application.GlobalSetting
|
||||
{
|
||||
@@ -14,6 +16,10 @@ namespace Yi.BBS.Application.GlobalSetting
|
||||
[AppService]
|
||||
public class TempService : ApplicationService, IAutoApiService
|
||||
{
|
||||
|
||||
public TempService(IDataSeed<UserEntity> dataSeed) {
|
||||
dataSeed.InvokerAsync().Wait();
|
||||
}
|
||||
///// <summary>
|
||||
///// 登录
|
||||
///// </summary>
|
||||
|
||||
@@ -11,6 +11,10 @@ using Yi.RBAC.Domain.Shared.Identity.EnumClasses;
|
||||
|
||||
namespace Yi.RBAC.Domain.DataSeeds
|
||||
{
|
||||
//支持依赖注入执行
|
||||
[AppService(typeof(IDataSeed<>))]
|
||||
|
||||
//支持启动时执行
|
||||
[AppService(typeof(IDataSeed))]
|
||||
public class UserDataSeed : AbstractDataSeed<UserEntity>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user