"查得到、但不用来学"的速查表:各配置对象的字段与默认值集中列在这里。想理解它们怎么配合,先读应用装配与数据层;本页只负责"某个字段叫什么、什么类型、默认是什么",方便 Ctrl+F。
AppInfo(AddKnown 的 option)
services.AddKnown(option => { ... }) 里的 option 就是 AppInfo。
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
Id |
string | 空 | 应用唯一标识;日志、埋点、SysConfig.AppId 隔离都认它 |
Name |
string | 空 | 展示名 |
Type |
AppType | Web |
枚举,仅 Web / Desktop |
Assembly |
Assembly | null | 主程序集;仅作溯源/展示,不等于扫描该程序集(扫描靠 Config.AddModule) |
CreateTime |
DateTime | 2020-07-10 |
建号时间戳,用于日志/统计,也是幂等种子的版本标记来源 |
ClientOption(AddKnownClient 的 option)
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
BaseAddress |
string | 空 | HttpClient 基地址;同源用 HostEnvironment.BaseAddress,约定结尾不带斜杠 |
ServerOption(AddKnownWeb / AddKnownDesktop 的 option)
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
WebRoot |
string | 空 | Web 根目录 |
ContentRoot |
string | 空 | 内容根目录 |
Assembly |
Assembly | null | 宿主程序集 |
Database |
Action<DatabaseOption> | null | 数据库配置回调;为 null 则不装配数据层 |
UseFileLogger(...) |
方法 | — | 开启文件日志,参数见下 |
UseFileLogger(directory, prefix = "known", maxBytesPerFile = 10MB, retainDays = 30, capacity = 0):directory 不存在则创建;maxBytesPerFile 超过则同日滚动到新序号文件(≤0 不按大小滚动);retainDays 按天保留、更早的自动清理(≤0 不删);capacity 内存队列背压阈值(≤0 取默认 65536)。该方法标注了 [UnsupportedOSPlatform("browser")],只在 Server / Desktop 进程用。
DatabaseOption(ServerOption.Database 回调里的 db)
字段:
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
Databases |
List<DatabaseInfo> | 空 | 已登记的连接(Add* 会往这里加) |
SqlMonitors |
List<Action<CommandInfo>> | 空 | SQL 执行监视器(打印/追踪语句) |
OperateMonitors |
List<Action<DbOperateInfo>> | 空 | 数据变更监视器(增删改快照) |
MaxDeleteMonitorItems |
int | 1000 | 删除监视快照最多记多少条,防大表删爆内存(≤0 不限) |
DefaultAppId |
string | null | 写实体 AppId 的默认值;未设回退宿主 Config.App.Id |
IsMemoryDatabase |
bool? | null | 是否内存库(需保持连接存活);未设按连接串推断 |
连接登记方法(都返回 void,泛型参数是 ADO.NET 的 DbProviderFactory 类型,如 Microsoft.Data.Sqlite.SqliteFactory):
| 方法 | 对应 DatabaseType |
|---|---|
AddSQLite<TProvider>(connString, name = "Default") |
SQLite |
AddSQLServer<TProvider>(...) |
SQLServer |
AddMySQL<TProvider>(...) |
MySQL |
AddPostgreSQL<TProvider>(...) |
PostgreSQL |
AddOracle<TProvider>(...) |
Oracle |
AddDM<TProvider>(...) |
DM(达梦) |
AddAccess<TProvider>(...) |
Access |
name 是多连接名(默认常量 Database.DefaultConnName = "Default");底层还有更原始的 AddProvider<TProvider>(name, type, connString) 与只注册工厂的 AddFactory<TProvider>(type)。
Config 静态门面(装配期声明一次、全站生效)
| 成员 | 类型 | 默认 | 说明 |
|---|---|---|---|
Config.App |
AppInfo | new() | 当前应用元信息(只读,由 AddKnown 写入) |
Config.LayoutType |
Type | typeof(AdminLayout) |
默认布局:用户在顶栏选过外壳时以他的选择为准,这里只是没选过时的落点;营销站等自定义 Config.LayoutType 不受后台门禁约束 |
Config.Shells |
List<ShellOption> | admin / rail 两项 | 可切换的外壳候选(顶栏头像下拉「布局」逐条渲染);清到不足两项即收起入口、旧偏好一并作废 |
Config.AddShell(key, name, type, icon, order) |
方法 | icon→layout | 登记一个可选外壳;同 key 覆盖。type 是外壳组件类型,后台模板请继承 AppShell |
Config.AppHomeRoute |
string | "/app" |
移动端首页路由;登录判为移动端后跳这里 |
Config.Assemblies |
List<Assembly> | 空 | 已登记扫描的程序集 |
Config.AddModule<T>() / AddModule(Assembly) |
方法 | — | 扫 [WebApi]/[Service]/[Table]/[Menu]/[AppMenu];T 须为非静态 marker 类型 |
Config.AddMenuGroup(id, name, icon, order, parent) |
方法 | icon→folder / order=0 | 声明一个菜单分组,页面 [Menu].Group 按 id 引用;同 id 覆盖 |
Config.AddTopAction(id, name, icon, handler, url, order, component, roles) |
方法 | icon→more | 顶栏右上角一个功能,声明一次全站出现;component>handler>url 择一生效 |
Config.AddMenuDecorator(Action<MenuItem>) |
方法 | — | 菜单树装配后逐项加工(徽标/计数/显隐),派生值从唯一真相源现算 |
LocalInfo(LocalService.Info)
用户可见的界面偏好快照:
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
Theme |
string | "light" |
"light" / "dark" |
Language |
string | "zh-CN" |
当前语言 |
Density |
string | "middle" |
"small" / "middle" / "large" |
Color |
string | "" |
强调色十六进制(如 #7C5CFF);空表示沿用主题默认色 |
MultiTabs |
bool | false | 导航形态:false 单页、true 多页签(落 known.multitabs) |
Layout |
string | "" |
当前外壳标识(对应 Config.Shells 某项的 Key,落 known.layout);空表示没选过,外壳落回 Config.LayoutType |
IsMobile |
bool | false | 是否判定为移动端 |
IsDark |
bool | 派生 | Theme == "dark" |
组件通用属性(BaseComponent,所有组件都认)
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
Class |
string | null | 追加 CSS 类 |
Style |
string | null | 内联样式 |
Disabled |
bool | false | 禁用态 |
Visible |
bool | true | 是否渲染(注意源码注释误写 false,以 = true 为准) |
VisibleChanged |
EventCallback<bool> | — | 可见性变更回调 |
UserAttributes |
Dictionary<string,object> | null | 未知 attribute 透传到根元素 |
另外每个组件都 [Inject] 了 UI(UIService)与 Local(LocalService),无需手动传。详见组件通用约定。
UIService 全局浮层可调项
| 属性 | 默认 | 说明 |
|---|---|---|
Duration |
2500 | Toast 自动关闭毫秒(0 不关;Error 类型强制 ≥5000) |
ToastPlacement |
"top" |
Toast 停靠:top / bottom(均水平居中) |
ToastClosable |
true | Toast 是否带手动关闭按钮 |
ToastMax |
5 | Toast 同屏最多条数 |
NotificationDuration |
4500 | 卡片通知自动关闭毫秒 |
NotificationPlacement |
"topRight" |
通知角落:topRight/bottomRight/topLeft/bottomLeft |
NotificationMax |
5 | 通知同屏最多条数 |
LoadingColor |
"primary" |
进度条色:primary/success/warning/danger/info |
结果与分页模型
Result(服务层统一返回):
| 成员 | 类型 | 默认 | 说明 |
|---|---|---|---|
IsClose |
bool | true | 是否关闭当前弹窗/抽屉 |
IsValid |
bool | true | 操作是否成功(判定用这个,不是 Success) |
Message |
string | — | 消息;多条 AddError 会以换行拼接 |
Data |
object | null | 附带数据 |
DataAs<T>() |
方法 | — | 把 Data 转成 T(不同类型走 JSON 反序列化) |
AddError(msg) / Validate(broken, msg) |
方法 | — | 追加错误(会把 IsValid 置 false) |
Result.Error(msg, data) / Result.Success(msg, data) |
静态 | — | 快捷构造 |
PagingCriteria(分页入参):PageIndex=1、PageSize=20、StartIndex=0(>0 时覆盖偏移)、IsPaging=true、OrderBys("字段 asc|desc")、EntityType、Fields(属性名→列名)、Parameters(@ 开头);派生 IsValidPaging 与 GetStartIndex()。PagingResult<T>:Total、Data、Message、IsValid。
实体公共列
EntityBase(继承即自带):Id[Key]、CreateBy、CreateTime、ModifyBy、ModifyTime、Version、Extension、AppId、CompNo,以及 Validate()。其基类 BaseEntity 提供 IsNew(默认 true)与 FillModel(model)。Id 及外键按项目约定用 string varchar(50) 存 GUID(勿用 Guid 类型)。数据层细节见数据层与 Database 契约。
扫码关注公众号
扫码加入 QQ 群