Use IModule register modules

This commit is contained in:
lihanbo 2024-10-16 11:27:14 +08:00
parent cf7ebb3cbc
commit 0d5dc03030
6 changed files with 90 additions and 70 deletions

View File

@ -6,7 +6,7 @@ using Serilog;
using Serilog.Core;
namespace LFlow.Home.Controllers;
public class HomeController(IHomeService<HomeDto, string> service, ILogger logger) : BaseController
public class HomeController(IHomeService<HomeDto, string> service, ILogger logger)
{
[HttpGet]
public string Home(string id)

30
LFlow.Home/HomeModule.cs Normal file
View File

@ -0,0 +1,30 @@
using System;
using System.Reflection;
using LFlow.Base.BusinessInterface;
using LFlow.Base.Interfaces;
using LFlow.Base.Utils;
using LFlow.Home.Models.DataModels;
using LFlow.Home.Models.DtoModel;
using LFlow.Home.Services;
using Microsoft.Extensions.DependencyInjection;
namespace LFlow.Home;
public class HomeModule : IModule
{
public void ConfigureModule(IServiceCollection services)
{
// 将HomeModel注册到CodeFirst将会在程序启动后自动创建表
CodeFirst.AddType(typeof(HomeModel));
var assembly = Assembly.GetAssembly(typeof(HomeService))!;
var types = assembly.GetTypes().ToList();
RegisterModule.RegisterAllService(types, services);
RegisterModule.RegisterAllRepo(types, services);
RegisterModule.RegisterAllModule(types, services);
services.AddControllers().AddApplicationPart(assembly);
Console.WriteLine("HomeModule ConfigureModule");
}
}

View File

@ -5,11 +5,26 @@ namespace LFlow.Home.Models.DtoModel;
public class HomeDto : IModel
{
public string? Id { get; set; }
public string? Id
{
get; set;
}
public string? ModuleName
{
get; set;
}
public string? ModuleUrl
{
get; set;
}
public string? ModuleVer
{
get; set;
}
public override string ToString()
{
return $"HomeDto {Id}";
return $"HomeDto {Id} _ {ModuleName} _ {ModuleUrl} _ {ModuleVer}";
}
}

View File

@ -1,4 +1,5 @@
using System;
using LFlow.Base.Default;
using LFlow.Base.Interfaces;
// using LFlow.Interfaces;
@ -7,33 +8,21 @@ using SqlSugar;
namespace LFlow.Home.Repositorys;
public class HomeRepo(ISqlSugarClient db) : IRepo<HomeModel, string>
public class HomeRepo(ISqlSugarClient db) : DefaultCurdRepo<HomeModel, string>(db)
{
public HomeModel Delete(string id)
{
throw new NotImplementedException();
}
public HomeModel Get(string id)
{
return new HomeModel
{
Id = id
};
}
public HomeModel SaveOrUpdate(HomeModel entity, bool isUpdate)
{
throw new NotImplementedException();
}
public List<HomeModel> Search(HomeModel whereObj)
{
throw new NotImplementedException();
}
public List<string> WhereSearchId(HomeModel whereObj)
{
throw new NotImplementedException();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="whereObj"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override List<HomeModel> Search(HomeModel whereObj) => throw new NotImplementedException();
/// <summary>
/// 根据条件查询ID
/// </summary>
/// <param name="whereObj"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override List<string> WhereSearchId(HomeModel whereObj) => throw new NotImplementedException();
}

View File

@ -7,31 +7,33 @@ using LFlow.Home.Models.DataModels;
using LFlow.Home.Models.DtoModel;
using LFlow.Base.BusinessInterface;
using Serilog;
using Microsoft.AspNetCore.Mvc;
namespace LFlow.Home.Services;
public class HomeService(IRepo<HomeModel, string> repo, ILogger logger) : IHomeService<HomeDto, string>
public class HomeService(IRepo<HomeModel, string> repo, ILogger logger) : BaseController, IHomeService<HomeDto?, string>
{
public HomeDto DeleteById(string id)
[HttpGet]
public HomeDto? DeleteById(string id)
{
var result = repo.Delete(id);
return Mapper.Map<HomeDto>(result);
}
public HomeDto GetById(string id)
[HttpGet]
public HomeDto? GetById(string id)
{
logger.Information($"GetById id -> {id}");
var result = repo.Get(id);
return Mapper.Map<HomeDto>(result);
}
public HomeDto Save(HomeDto entity)
[HttpPost]
public HomeDto? Save(HomeDto entity)
{
var result = repo.SaveOrUpdate(Mapper.Map<HomeModel>(entity), false);
return Mapper.Map<HomeDto>(result);
}
public List<HomeDto> Search(HomeDto whereObj)
[HttpGet]
public List<HomeDto>? Search(HomeDto whereObj)
{
throw new NotImplementedException();
}

View File

@ -1,41 +1,25 @@
using System;
using LFlow.Base.Default;
using LFlow.Base.Interfaces;
using LFlow.User.Model.DataModel;
using SqlSugar;
namespace LFlow.User.Repositorys;
public class UserRepo(ISqlSugarClient db) : IRepo<UserModel, string>
public class UserRepo(ISqlSugarClient db) : DefaultCurdRepo<UserModel, string>(db)
{
public UserModel Delete(string id)
{
throw new NotImplementedException();
}
public UserModel Get(string id)
{
return new UserModel
{
UserID = id,
UserName = "Test User",
UserNickName = "Tester",
EmailAddress = "Test@Ling.chat",
};
}
public UserModel SaveOrUpdate(UserModel entity, bool isUpdate)
{
throw new NotImplementedException();
}
public List<UserModel> Search(UserModel whereObj)
{
throw new NotImplementedException();
}
public List<string> WhereSearchId(UserModel whereObj)
{
throw new NotImplementedException();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="whereObj"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override List<UserModel> Search(UserModel whereObj) => throw new NotImplementedException();
/// <summary>
/// 根据条件查询ID
/// </summary>
/// <param name="whereObj"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override List<string> WhereSearchId(UserModel whereObj) => throw new NotImplementedException();
}