--安装模板
dotnet new install KnownTemplate
--创建项目
--host参数:full(默认)/hosted/server/winform
dotnet new known --name=KIMS --host=hosted
说明:KIMS为测试项目名称
├─KIMS -> 项目前后端共用库,客户端和实体类等。
├─KIMS.Client -> Web前端,Blazor WebAssembly。
├─KIMS.Core -> 项目后端库,控制器、服务、数据访问等。
├─KIMS.Razor -> 项目前端库,模块页面和表单。
├─KIMS.Server -> Web后端。
├─KIMS.sln -> VS解决方案文件。
public class AppConfig
{
public static void Initialize()
{
Config.AppId = "KIMS"; //系统ID,自动生成,默认项目名称
Config.AppName = "Known管理系统"; //在此配置你的系统名称
Config.SetAppAssembly(typeof(AppConfig).Assembly); //App程序集,自动获取版本,反射实体模型用于模块管理配置列表字段
PagingCriteria.DefaultPageSize = 20; //默认分页大小
DicCategory.AddCategories<AppDictionary>(); //自动加载数据字典类别,在AppDictionary中增加类别
Cache.AttachCodes(typeof(AppConfig).Assembly); //自动加载CodeTable特性类常量进入缓存
//在此配置你的系统其他全局配置
}
}
-- SQLite
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.11" />
-- MySQL
<PackageReference Include="MySqlConnector" Version="2.2.7" />
-- Access
<PackageReference Include="System.Data.OleDb" Version="7.0.0" />
-- SQLServer
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
class AppServer
{
internal static void Initialize(WebApplicationBuilder builder)
{
//配置环境目录
KCConfig.WebRoot = builder.Environment.WebRootPath;
KCConfig.ContentRoot = builder.Environment.ContentRootPath;
//读取appsettings.json配置
var configuration = builder.Configuration;
var dbFile = configuration.GetSection("DBFile").Get<string>();//数据库配置
var uploadPath = configuration.GetSection("UploadPath").Get<string>();//上传文件存储路径
Initialize(dbFile, uploadPath);
}
internal static void Initialize(string? dbFile, string? uploadPath)
{
//初始化配置
AppConfig.Initialize();
AppCore.Initialize();
//转换绝对路径
var path = KCConfig.ContentRoot;
dbFile = Path.GetFullPath(Path.Combine(path, dbFile));
uploadPath = Path.GetFullPath(Path.Combine(path, uploadPath));
//注册数据访问提供者和初始化数据库连接
Database.RegisterProviders(new Dictionary<string, Type>
{
["SQLite"] = typeof(Microsoft.Data.Sqlite.SqliteFactory)
});
var connInfo = new Known.Core.ConnectionInfo
{
Name = "Default",
ProviderName = "SQLite",
ConnectionString = $"Data Source={dbFile};"
};
KCConfig.App = new AppInfo
{
Connections = new List<Known.Core.ConnectionInfo> { connInfo },
UploadPath = uploadPath
};
}
}