Known是基于C#和Blazor开发的前后端分离快速开发框架,开箱即用,跨平台,一处代码,多处运行。
开源地址: https://gitee.com/known/Known
-- 安装模板
dotnet new install KnownTemplate
-- 创建项目
dotnet new known --name=KIMS
说明:KIMS为测试项目名称
├─KIMS ->项目前后端共用库,客户端和实体类等。
├─KIMS.Client ->Web前端,Blazor WebAssembly。
├─KIMS.Core ->项目后端库,控制器、服务、数据访问等。
├─KIMS.Razor ->项目前端库,模块页面和表单。
├─KIMS.Server ->Web后端。
├─KIMS.WinForm ->WinForm窗体及Razor页面。
├─KIMSAlone ->桌面exe程序。
├─KIMS.db ->默认SQLite数据库。
├─KIMS.sln ->VS解决方案文件。
public class AppConfig
{
public static void Initialize()
{
Config.AppId = "KIMS"; //系统ID,自动生成,默认项目名称
Config.AppName = "Known管理系统"; //在此配置你的系统名称
Config.SysVersion = "1.0.0"; //系统版本号
Config.AppAssembly = typeof(AppConfig).Assembly; //实体模型程序集,用于模块管理配置列表字段
PagingCriteria.DefaultPageSize = 20; //默认分页大小
DicCategory.AddCategories<AppDictionary>(); //自动加载数据字典类别,在AppDictionary中增加类别
Cache.AttachCodes(typeof(AppConfig).Assembly); //自动加载CodeTable特性类常量进入缓存
//在此配置你的系统其他全局配置
}
}
-- SQLite
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.5" />
-- Access
<PackageReference Include="System.Data.OleDb" Version="7.0.0" />
-- MySQL
<PackageReference Include="MySqlConnector" Version="2.2.5" />
-- 打开项目下 AppServer.cs 文件修改数据库连接,示例代码如下:
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
};
}
}