Move LFlow to LFlow.Base

This commit is contained in:
lihanbo 2024-10-16 11:35:05 +08:00
parent 1a362319d0
commit e49fff6407
24 changed files with 210 additions and 241 deletions

View File

@ -1,15 +1,15 @@
using System;
namespace LFlow.Base;
/// <summary>
/// 程序对象
/// </summary>
public class App
{
public static IServiceCollection? services;
private static IServiceProvider? ServiceProvider => services?.BuildServiceProvider();
public static T? GetService<T>()
{
return ServiceProvider!.GetService<T>();
}
}
using System;
namespace LFlow.Base;
/// <summary>
/// 程序对象
/// </summary>
public class App
{
public static IServiceCollection? services;
private static IServiceProvider? ServiceProvider => services?.BuildServiceProvider();
public static T? GetService<T>()
{
return ServiceProvider!.GetService<T>();
}
}

View File

@ -1,18 +1,18 @@
using System;
using Microsoft.AspNetCore.Mvc;
namespace LFlow.Base.Interfaces;
/// <summary>
/// 基础控制器
/// </summary>
/// <example>
/// [Route("api/[controller]/[action]")]
/// [ApiController]
/// </example>
[Route("api/[controller]/[action]")]
[ApiController]
public abstract class BaseController : ControllerBase, IController
{
}
using System;
using Microsoft.AspNetCore.Mvc;
namespace LFlow.Base.Interfaces;
/// <summary>
/// 基础控制器
/// </summary>
/// <example>
/// [Route("api/[controller]/[action]")]
/// [ApiController]
/// </example>
[Route("api/[controller]/[action]")]
[ApiController]
public abstract class BaseController : ControllerBase, IController
{
}

View File

@ -1,16 +1,16 @@
using System;
using LFlow.Base.Interfaces;
namespace LFlow.Base.BusinessInterface;
/// <summary>
/// Home service interface
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="K"></typeparam>
public interface IHomeService<T, K> : IService<T> where T : IModel
{
T DeleteById(K id);
T GetById(K id);
}
using System;
using LFlow.Base.Interfaces;
namespace LFlow.Base.BusinessInterface;
/// <summary>
/// Home service interface
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="K"></typeparam>
public interface IHomeService<T, K> : IService<T> where T : IModel
{
T DeleteById(K id);
T GetById(K id);
}

View File

@ -1,8 +1,8 @@
using System;
namespace LFlow.Base.Interfaces.BusinessInterface;
public interface IUserService<T> : IService<T> where T : IModel
{
}
using System;
namespace LFlow.Base.Interfaces.BusinessInterface;
public interface IUserService<T> : IService<T> where T : IModel
{
}

View File

@ -1,11 +1,11 @@
using System;
namespace LFlow.Base.Interfaces;
/// <summary>
/// 控制器接口
/// </summary>
public interface IController
{
}
using System;
namespace LFlow.Base.Interfaces;
/// <summary>
/// 控制器接口
/// </summary>
public interface IController
{
}

View File

@ -1,11 +1,11 @@
using System;
namespace LFlow.Base.Interfaces;
/// <summary>
/// 数据模型接口 Repo层用
/// </summary>
public interface IDataModel : IModel
{
}
using System;
namespace LFlow.Base.Interfaces;
/// <summary>
/// 数据模型接口 Repo层用
/// </summary>
public interface IDataModel : IModel
{
}

View File

@ -1,11 +1,11 @@
using System;
namespace LFlow.Base.Interfaces;
/// <summary>
/// 模型顶层接口 Service层用
/// </summary>
public interface IModel
{
}
using System;
namespace LFlow.Base.Interfaces;
/// <summary>
/// 模型顶层接口 Service层用
/// </summary>
public interface IModel
{
}

View File

@ -1,51 +1,51 @@
using System;
namespace LFlow.Base.Interfaces;
/// <summary>
/// 通用的仓库对象接口
/// </summary>
/// <typeparam name="T">数据模型</typeparam>
/// <typeparam name="K">主键</typeparam>
public interface IRepo<T, K> where T : IDataModel
{
/// <summary>
/// 获取单个对象
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
T Get(K id);
/// <summary>
/// 删除单个对象
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
int Delete(K id);
/// <summary>
/// 保存与更新
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
T SaveOrUpdate(T entity, bool isUpdate);
/// <summary>
/// 获取所有对象列表(默认分页)
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
List<T> GetAll(int pageIndex, int pageSize, ref int pageTotal);
/// <summary>
/// 根据条件搜索对象列表
/// </summary>
/// <param name="whereObj"></param>
/// <returns></returns>
List<T> Search(T whereObj);
/// <summary>
/// 根据条件搜索主键列表
/// </summary>
/// <param name="whereObj"></param>
/// <returns></returns>
List<K> WhereSearchId(T whereObj);
}
using System;
namespace LFlow.Base.Interfaces;
/// <summary>
/// 通用的仓库对象接口
/// </summary>
/// <typeparam name="T">数据模型</typeparam>
/// <typeparam name="K">主键</typeparam>
public interface IRepo<T, K> where T : IDataModel
{
/// <summary>
/// 获取单个对象
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
T Get(K id);
/// <summary>
/// 删除单个对象
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
int Delete(K id);
/// <summary>
/// 保存与更新
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
T SaveOrUpdate(T entity, bool isUpdate);
/// <summary>
/// 获取所有对象列表(默认分页)
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
List<T> GetAll(int pageIndex, int pageSize, ref int pageTotal);
/// <summary>
/// 根据条件搜索对象列表
/// </summary>
/// <param name="whereObj"></param>
/// <returns></returns>
List<T> Search(T whereObj);
/// <summary>
/// 根据条件搜索主键列表
/// </summary>
/// <param name="whereObj"></param>
/// <returns></returns>
List<K> WhereSearchId(T whereObj);
}

View File

@ -1,12 +1,12 @@
using System;
namespace LFlow.Base.Interfaces;
public interface IService<T> where T : IModel
{
T GetById(string id);
List<T> Search(T whereObj);
T DeleteById(string id);
T Save(T entity);
}
using System;
namespace LFlow.Base.Interfaces;
public interface IService<T> where T : IModel
{
T GetById(string id);
List<T> Search(T whereObj);
T DeleteById(string id);
T Save(T entity);
}

View File

@ -1,32 +1,32 @@
using System;
using System.Collections.Concurrent;
using System.Net;
using Serilog;
using SqlSugar;
namespace LFlow.Base.Utils;
public static class CodeFirst
{
// 线程安全的类型列表
private static readonly ConcurrentBag<Type> _types = new();
public static void AddType(Type type)
{
_types.Add(type);
}
internal static void InitTable()
{
var logger = App.GetService<Serilog.ILogger>()!;
var db = App.GetService<ISqlSugarClient>()!;
foreach (var type in _types)
{
db.CodeFirst.InitTables(type);
logger.Information($"Init table {type.Name} success");
}
}
internal static void InitDBSeed()
{
//TODO: Seed data
}
}
using System;
using System.Collections.Concurrent;
using System.Net;
using Serilog;
using SqlSugar;
namespace LFlow.Base.Utils;
public static class CodeFirst
{
// 线程安全的类型列表
private static readonly ConcurrentBag<Type> _types = new();
public static void AddType(Type type)
{
_types.Add(type);
}
internal static void InitTable()
{
var logger = App.GetService<Serilog.ILogger>()!;
var db = App.GetService<ISqlSugarClient>()!;
foreach (var type in _types)
{
db.CodeFirst.InitTables(type);
logger.Information($"Init table {type.Name} success");
}
}
internal static void InitDBSeed()
{
//TODO: Seed data
}
}

View File

@ -1,22 +1,22 @@
using System;
using Mapster;
namespace LFlow.Base.Utils;
public class Mapper
{
/// <summary>
/// 将一个对象映射到另一个对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public static T? Map<T>(object source)
{
if (source == null)
{
return default;
}
return source.Adapt<T>();
}
}
using System;
using Mapster;
namespace LFlow.Base.Utils;
public class Mapper
{
/// <summary>
/// 将一个对象映射到另一个对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public static T? Map<T>(object source)
{
if (source == null)
{
return default;
}
return source.Adapt<T>();
}
}

View File

@ -20,7 +20,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LFlow\LFlow.Base.csproj" />
<ProjectReference Include="..\LFlow.Base\LFlow.Base.csproj" />
</ItemGroup>
</Project>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\LFlow\LFlow.Base.csproj" />
<ProjectReference Include="..\LFlow.Base\LFlow.Base.csproj" />
</ItemGroup>
<PropertyGroup>

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Base", "LFlow\LFlow.Base.csproj", "{C581AFB2-50BA-4357-AD0A-AF287194837D}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Base", "LFlow.Base\LFlow.Base.csproj", "{C581AFB2-50BA-4357-AD0A-AF287194837D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Home", "LFlow.Home\LFlow.Home.csproj", "{1F607791-03F0-45EA-8F13-A085E2D49DD4}"
EndProject

View File

@ -1,19 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "dotnet: build",
"program": "${workspaceFolder}/bin/Debug/net8.0/LFlow.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
},
]
}

View File

@ -1,12 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "dotnet",
"task": "build",
"group": "build",
"problemMatcher": [],
"label": "dotnet: build"
}
]
}