DoconutOptions
配置 Doconut 服务
DoconutOptions (namespace Doconut) 是整个 SDK 的唯一配置对象。您只需在 AddDoconut() 中配置一次,它将作为单例注册。
builder.Services.AddDoconut(options =>
{
options.LicensePath = "Doconut.Viewer.lic";
options.UnsafeMode = false;
options.ShowDoconutInfo = false;
options.AddPlugin<Doconut.Plugins.Dicom.DicomPlugin>();
});属性
| 类型 | 属性 | 默认值 | 描述 |
|---|---|---|---|
bool | ShowDoconutInfo | false | 当 true 时,未带令牌的中间件请求返回版本横幅(Doconut <version> is running on <host>),而不是 404。可用作快速检查;在生产环境中保留 false。 |
bool | UnsafeMode | false | 当 true 时,跳过页面请求的 ASP.NET 会话安全检查。在生产环境中保留 false(参见 Core Concepts → Sessions & Security)。 |
string | MiddlewarePath | "/doconut" | 页面-图像端点的协调值。该值会被验证,但不会挂载管道分支;请保持其与实际的 UseDoconut() 映射和客户端 BasePath 对齐。 |
string | ResourcesPath | "/doconut-res" | 嵌入式 JS/CSS/图像/字体资源的 URL 路径前缀。 |
string | LicensePath | "" | 许可证文件的路径。为空 → 使用下一个许可证来源,然后自动发现;若未找到 → 进入带水印的评估状态,且无任何功能。 |
string | LicenseContent | "" | 原始 XML 许可证内容(数据库、环境变量、密钥管理器)。优先于 LicensePath。 |
Stream? | LicenseStream | null | 许可证作为流,在启动时读取一次。优先于其他两种来源。 |
bool | ResetLicense | false | 保留的兼容性标志。当前的 .NET 6 实现不使用它;更换许可证后请重新启动应用程序。 |
DoconutPluginRegistry | PluginRegistry | — | 只读注册表,用于收集插件贡献;由查看器工厂使用。通过 AddPlugin<T>() 填充。 |
许可证优先级(在服务注册时强制执行):LicenseStream → LicenseContent → LicensePath → 自动发现(参见 Getting Started → License Setup)。
方法
AddPlugin<TPlugin>()
DoconutOptions AddPlugin<TPlugin>() where TPlugin : IDoconutPlugin, new()对已发布的可选 Converter 和 DICOM 包使用此方法。注释和普通搜索是内置的许可功能,不使用 AddPlugin<TPlugin>()。
注册一个第一方插件(Converter、DICOM)。采用流式写法——返回 options 实例。AddDoconut() 在缺少许可证、遗留 TRIAL 文件,或付费许可证未授予插件功能时抛出 InvalidOperationException。临时/演示注册在过期后仍会保留,并受运行时门控约束(参见 Core Concepts → Plugin System)。
可选的 Converter 小部件通过 AddConverterWidget() 启用,并通过只读的 ConverterWidget 属性暴露;其选项在 Converter Plugin 页面(Plugins → Converter Plugin)中有文档说明。
RegisterViewer(extension, factory, defaultConfig?)
DoconutOptions RegisterViewer(
string extension, // ".myext" — 前导点可选
Func<IFormatViewer> factory,
Func<BaseConfig>? defaultConfig = null)为文件扩展名注册一个 自定义查看器。自定义查看器优先于内置和插件查看器,并且不受许可证限制。当省略 defaultConfig 且文档在没有显式配置的情况下打开时,将使用 ImageConfig。
对于空扩展名抛出 ArgumentException(Extension must be a non-empty file extension.),对于空工厂抛出 ArgumentNullException。
启动验证
AddDoconut() 对选项进行 快速失败 验证,因此配置错误会在启动时以明确的异常出现,而不是在请求时产生令人困惑的 404。
DoconutOptions.MiddlewarePath must be a non-empty path starting with '/'.
DoconutOptions.ResourcesPath must be a non-empty path starting with '/'.
DoconutOptions.MiddlewarePath and ResourcesPath must be different paths.常见配置
// Production: 显式许可证,所有内容已锁定(所有安全默认)
builder.Services.AddDoconut(options =>
{
options.LicenseContent = builder.Configuration["Doconut:License"] ?? "";
});
// 自定义路径(例如,为避免路由冲突)
builder.Services.AddDoconut(options =>
{
options.MiddlewarePath = "/docs-engine";
options.ResourcesPath = "/docs-assets";
});当您更改 ResourcesPath 时,请保持客户端小部件的 ResPath 同步(参见 ViewerConfig)。
MiddlewarePath 不是自动的 ASP.NET Core 路由映射器。如果 Doconut 只应在自定义前缀下响应,请在该分支上挂载 UseDoconut()(例如使用 app.Map("/docs-engine", branch => branch.UseDoconut())),并将客户端 BasePath 设置为相同的 URL。
此页面对您有帮助吗?