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; using Serilog.Core;
namespace LFlow.Home.Controllers; namespace LFlow.Home.Controllers;
public class HomeController(IHomeService<HomeDto, string> service, ILogger logger) : BaseController public class HomeController(IHomeService<HomeDto, string> service, ILogger logger)
{ {
[HttpGet] [HttpGet]
public string Home(string id) 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 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() public override string ToString()
{ {
return $"HomeDto {Id}"; return $"HomeDto {Id} _ {ModuleName} _ {ModuleUrl} _ {ModuleVer}";
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using LFlow.Base.Default;
using LFlow.Base.Interfaces; using LFlow.Base.Interfaces;
// using LFlow.Interfaces; // using LFlow.Interfaces;
@ -7,33 +8,21 @@ using SqlSugar;
namespace LFlow.Home.Repositorys; 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) /// <summary>
{ /// 查询
return new HomeModel /// </summary>
{ /// <param name="whereObj"></param>
Id = id /// <returns></returns>
}; /// <exception cref="NotImplementedException"></exception>
} public override List<HomeModel> Search(HomeModel whereObj) => throw new NotImplementedException();
/// <summary>
public HomeModel SaveOrUpdate(HomeModel entity, bool isUpdate) /// 根据条件查询ID
{ /// </summary>
throw new NotImplementedException(); /// <param name="whereObj"></param>
} /// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public List<HomeModel> Search(HomeModel whereObj) public override List<string> WhereSearchId(HomeModel whereObj) => throw new NotImplementedException();
{
throw new NotImplementedException();
}
public 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.Home.Models.DtoModel;
using LFlow.Base.BusinessInterface; using LFlow.Base.BusinessInterface;
using Serilog; using Serilog;
using Microsoft.AspNetCore.Mvc;
namespace LFlow.Home.Services; 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); var result = repo.Delete(id);
return Mapper.Map<HomeDto>(result); return Mapper.Map<HomeDto>(result);
} }
[HttpGet]
public HomeDto GetById(string id) public HomeDto? GetById(string id)
{ {
logger.Information($"GetById id -> {id}"); logger.Information($"GetById id -> {id}");
var result = repo.Get(id); var result = repo.Get(id);
return Mapper.Map<HomeDto>(result); return Mapper.Map<HomeDto>(result);
} }
[HttpPost]
public HomeDto Save(HomeDto entity) public HomeDto? Save(HomeDto entity)
{ {
var result = repo.SaveOrUpdate(Mapper.Map<HomeModel>(entity), false); var result = repo.SaveOrUpdate(Mapper.Map<HomeModel>(entity), false);
return Mapper.Map<HomeDto>(result); return Mapper.Map<HomeDto>(result);
} }
[HttpGet]
public List<HomeDto> Search(HomeDto whereObj) public List<HomeDto>? Search(HomeDto whereObj)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -1,41 +1,25 @@
using System; using System;
using LFlow.Base.Default;
using LFlow.Base.Interfaces; using LFlow.Base.Interfaces;
using LFlow.User.Model.DataModel; using LFlow.User.Model.DataModel;
using SqlSugar; using SqlSugar;
namespace LFlow.User.Repositorys; 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) /// <summary>
{ /// 查询
throw new NotImplementedException(); /// </summary>
} /// <param name="whereObj"></param>
/// <returns></returns>
public UserModel Get(string id) /// <exception cref="NotImplementedException"></exception>
{ public override List<UserModel> Search(UserModel whereObj) => throw new NotImplementedException();
return new UserModel /// <summary>
{ /// 根据条件查询ID
UserID = id, /// </summary>
UserName = "Test User", /// <param name="whereObj"></param>
UserNickName = "Tester", /// <returns></returns>
EmailAddress = "Test@Ling.chat", /// <exception cref="NotImplementedException"></exception>
public override List<string> WhereSearchId(UserModel whereObj) => throw new NotImplementedException();
};
}
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();
}
} }