DoconutOptions
配置 Doconut 服务
DoconutOptions(命名空间 Doconut)是整个 SDK 的唯一配置对象。您只需在 AddDoconut() 中配置一次,它会以单例方式注册。
这既是位置的变化,也是形态的变化。在之前的 .NET Standard 库中,DoconutOptions 实例在管道阶段被构造并传递给 UseDoconut(new DoconutOptions { … })。而这里的中间件根本不接受任何选项——所有设置都在服务注册期间完成。
builder.Services.AddDoconut(options =>
{
options.LicensePath = "Doconut.Viewer.lic";
options.UnsafeMode = false;
options.ShowDoconutInfo = false;
options.AddPlugin<Doconut.Plugins.Dicom.DicomPlugin>();
});Properties
| 类型 | 属性 | 默认值 | 描述 |
|---|---|---|---|
bool | ShowDoconutInfo | false | 当 true 时,未携带令牌的中间件请求会返回版本横幅而不是 404。可用作快速检查;在生产环境中保留 false。 |
bool | UnsafeMode | false | 当 true 时,跳过页面请求的 ASP.NET 会话安全检查。在单节点生产环境中保留 false(参见 核心概念 → 会话与安全)。以前拼写为 UnSafeMode。 |
string | MiddlewarePath | "/doconut" | 页面图像端点的协调值。它会被验证,但不会挂载管道分支;请保持其与实际的 UseDoconut() 映射和客户端 BasePath 对齐。 |
string | ResourcesPath | "/doconut-res" | 嵌入式 JS/CSS/图像/字体资源的 URL 路径前缀。 |
string | LicensePath | "" | 许可证文件的路径。为空 → 使用下一个许可证来源,然后自动发现;未找到 → 处于带水印的评估状态,且无任何功能。 |
string | LicenseContent | "" | 原始 XML 许可证内容(数据库、环境变量、密钥管理器)。优先于 LicensePath。 |
Stream? | LicenseStream | null | 许可证作为流,在启动时读取一次。优先于其他两种来源。 |
bool | ResetLicense | false | 保留的兼容性标志。当前实现不使用它;更换许可证后请重启应用程序。 |
DoconutPluginRegistry | PluginRegistry | — | 只读注册表,用于收集插件贡献;由查看器工厂使用。通过 AddPlugin<T>() 填充。 |
许可证优先级(在服务注册时强制执行):LicenseStream → LicenseContent → LicensePath → 自动发现(参见 入门指南 → 许可证设置)。
Methods
AddPlugin<TPlugin>()
DoconutOptions AddPlugin<TPlugin>() where TPlugin : IDoconutPlugin, new()对已发布的可选 Converter 和 DICOM 包使用此方法。注释和普通搜索是内置的许可功能,不使用 AddPlugin<TPlugin>()。
注册一个第一方插件(Converter、DICOM)。采用流式接口——返回 options 实例。AddDoconut() 在缺少许可证、遗留 TRIAL 文件或付费许可证未授予插件功能时抛出 InvalidOperationException。临时/演示注册在过期后仍会保留,并受运行时门控约束(参见 核心概念 → 插件系统)。
可选的 Converter 小部件通过 AddConverterWidget() 启用,并通过只读的 ConverterWidget 属性暴露;其选项在 Converter Plugin 页面(插件 → Converter 插件)中有文档说明。
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.),当工厂为 null 时抛出 ArgumentNullException。
Startup validation
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.Common configurations
// 生产:显式许可证,所有内容均已锁定(所有安全默认设置)
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。参考应用程序则在带有 BasePath: '/' 的 MapWhen 分支上保留历史的 DocImage.axd 请求形态。
此页面对您有帮助吗?