DoconutOptions
配置 Doconut 服务
DoconutOptions(命名空间 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‑session 安全检查。生产环境请保持 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 8 实现不使用它;更换许可证后请重启应用程序。 |
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 插件页面(Plugins → Converter Plugin)中有文档说明。
RegisterViewer(extension, factory, defaultConfig?)
DoconutOptions RegisterViewer(
string extension, // ".myext" — leading dot optional
Func<IFormatViewer> factory,
Func<BaseConfig>? defaultConfig = null)为文件扩展名注册自定义查看器。自定义查看器优先于内置和插件查看器,且不受许可证限制。当省略 defaultConfig 且文档在没有显式配置的情况下打开时,会使用 ImageConfig。
如果扩展名为空会抛出 ArgumentException(Extension must be a non-empty file extension.),如果工厂为 null 会抛出 ArgumentNullException。
启动验证
AddDoconut() 采用 fail‑fast 验证选项,因此配置错误会在启动时以明确的异常形式出现,而不是在请求时产生令人困惑的 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: explicit license, everything locked down (all security defaults)
builder.Services.AddDoconut(options =>
{
options.LicenseContent = builder.Configuration["Doconut:License"] ?? "";
});
// Custom paths (e.g. to avoid a route conflict)
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。
此页面有帮助吗?