Add User proj

This commit is contained in:
Ling 2024-10-09 16:46:49 +08:00
parent 07bef1e52d
commit cf5bb3bc7c
19 changed files with 422 additions and 18 deletions

294
.gitignore vendored
View File

@ -1,3 +1,291 @@
/LFLow_Bin/
*/bin/*
*/obj/*
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
# VS Code
.vscode/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Typescript v1 declaration files
typings/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
/LF[Ll]ow_Bin/

View File

@ -1,12 +1,14 @@
using LFlow.Base.BusinessInterface;
using LFlow.Base.Interfaces;
using LFlow.Home.Models.DtoModel;
using Microsoft.AspNetCore.Mvc;
namespace LFlow.Home.Controllers;
public class HomeController : BaseController
public class HomeController(IHomeService<HomeDto, string> service) : BaseController
{
[HttpGet("/")]
public string Home()
[HttpGet("/[controller]/")]
public string Home(string id)
{
return "Home";
return service?.GetById(id)?.ToString() ?? "No service";
}
}

View File

@ -4,15 +4,14 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputPath>../LFLow_Bin/Services/</OutputPath>
<OutputPath>../LFlow_Bin/Services/</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<UseCommonOutputDirectory>true</UseCommonOutputDirectory>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<UseCommonOutputDirectory>true</UseCommonOutputDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mapster" Version="7.4.0" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="SQLite" Version="3.13.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.169" />
@ -22,6 +21,7 @@
<ItemGroup>
<ProjectReference Include="..\LFlow\LFlow.Base.csproj" />
<ProjectReference Include="..\LFlow.Interfaces\LFlow.Interfaces.csproj" />
</ItemGroup>
</Project>

View File

@ -4,5 +4,14 @@ namespace LFlow.Home.Models.DataModels;
public class HomeModel : IDataModel
{
/// <summary>
/// ID
/// </summary>
public string? Id { get; set; }
public override string ToString()
{
return $"HomeModel {Id}";
}
}

View File

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

View File

@ -15,7 +15,10 @@ public class HomeRepo : IRepo<HomeModel, string>
public HomeModel Get(string id)
{
throw new NotImplementedException();
return new HomeModel
{
Id = id
};
}
public HomeModel SaveOrUpdate(HomeModel entity, bool isUpdate)

View File

@ -6,10 +6,11 @@ using LFlow.Home.Models.DataModels;
// using LFlow.Interfaces;
using LFlow.Home.Models.DtoModel;
using LFlow.Base.BusinessInterface;
namespace LFlow.Home.Services;
public class HomeService(IRepo<HomeModel, string> repo) //: IHomeService
public class HomeService(IRepo<HomeModel, string> repo) : IHomeService<HomeDto, string>
{
public HomeDto DeleteById(string id)
{

View File

@ -0,0 +1,9 @@
using LFlow.Base.Interfaces;
namespace LFlow.User.Controllers
{
public class UserController : BaseController
{
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\LFlow\LFlow.Base.csproj" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputPath>../LFlow_Bin/Services/</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<UseCommonOutputDirectory>true</UseCommonOutputDirectory>
</PropertyGroup>
<ItemGroup>
<Folder Include="Services/" />
</ItemGroup>
</Project>

View File

@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Base", "LFlow\LFlow.B
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.Home", "LFlow.Home\LFlow.Home.csproj", "{1F607791-03F0-45EA-8F13-A085E2D49DD4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LFlow.User", "LFlow.User\LFlow.User.csproj", "{AC877BA7-45B8-4F8A-921E-6F11AC7A3638}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -21,6 +23,10 @@ Global
{1F607791-03F0-45EA-8F13-A085E2D49DD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F607791-03F0-45EA-8F13-A085E2D49DD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F607791-03F0-45EA-8F13-A085E2D49DD4}.Release|Any CPU.Build.0 = Release|Any CPU
{AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC877BA7-45B8-4F8A-921E-6F11AC7A3638}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -3,6 +3,13 @@ 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

@ -0,0 +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);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -5,14 +5,13 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputPath>../LFLow_Bin/</OutputPath>
<OutputPath>../LFlow_Bin/</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mapster" Version="7.4.0" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="SQLite" Version="3.13.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.169" />

View File

@ -82,10 +82,21 @@ public static class Program
var interfaces = type.GetInterfaces();
foreach (var inter in interfaces)
{
if (inter.Name.Contains("IService"))
Console.WriteLine();
Console.WriteLine(inter.Name);
Console.WriteLine(type.Name);
if (inter.Name.Contains("IRepo"))
{
//注册数据仓库
services.AddScoped(inter, type);
}
if (inter.Name.Contains(type.Name))
{
//注册服务
services.AddScoped(inter, type);
Console.WriteLine(inter);
Console.WriteLine(type);
}
if (inter.Name.Contains("IController"))
{

View File

@ -14,7 +14,17 @@ public class Mapper
public static T Map<T>(object source)
{
// 使用 Mapster 转换
var destination = source.Adapt<T>();
return destination;
// Check if the type is immutable
if (typeof(T).IsValueType || typeof(T).IsPrimitive || typeof(T) == typeof(string))
{
var dest = default(T);
// Use MapWith for immutable types
return source.Adapt(dest);
}
else
{
// Use Adapt for other types
return source.Adapt<T>();
}
}
}