DoconutOptions

Configure the Doconut services

DoconutOptions(命名空间 Doconut)是整个 SDK 的唯一配置对象。您只需在 AddDoconut() 中配置一次,它会以单例方式注册。

csharp
builder.Services.AddDoconut(options =>
{
    options.LicensePath     = "Doconut.Viewer.lic";
    options.UnsafeMode      = false;
    options.ShowDoconutInfo = false;
    options.AddPlugin<Doconut.Plugins.Dicom.DicomPlugin>();
});

属性

类型属性默认值描述
boolShowDoconutInfofalse当设为 true 时,未携带令牌的 middleware 请求会返回版本横幅(Doconut <version> 正在 <host> 上运行),而不是 404。可用于快速检查;在生产环境中保持 false
boolUnsafeModefalse当设为 true 时,页面请求会跳过 ASP.NET 会话安全检查。生产环境请保持 false(参见核心概念 → 会话与安全)。
stringMiddlewarePath"/doconut"页面-图像端点的协调值。虽然会进行验证,但不会挂载管道分支;请保持其与实际的 UseDoconut() 映射和客户端 BasePath 一致。
stringResourcesPath"/doconut-res"嵌入式 JS/CSS/图像/字体资源的 URL 路径前缀。
stringLicensePath""许可证文件的路径。为空 → 使用下一个许可证来源,然后自动发现;若未找到任何许可证 → 进入带水印的评估状态,且无任何功能。
stringLicenseContent""原始 XML 许可证内容(数据库、环境变量、密钥管理器)。优先于 LicensePath
Stream?LicenseStreamnull以流形式提供的许可证,在启动时读取一次。优先于上述两种来源。
boolResetLicensefalse保留的兼容性标志。当前 .NET 6 实现并不使用它;更换许可证后请重新启动应用程序。
DoconutPluginRegistryPluginRegistry只读注册表,用于收集插件贡献;由查看器工厂使用。通过 AddPlugin<T>() 填充。

许可证优先级(在服务注册时强制执行):LicenseStreamLicenseContentLicensePath → 自动发现(参见 入门 → 许可证设置)。

方法

AddPlugin<TPlugin>()

text
DoconutOptions AddPlugin<TPlugin>() where TPlugin : IDoconutPlugin, new()

对已发布的可选 Converter 和 DICOM 包使用此方法。注释和普通搜索是内置的授权功能,不使用 AddPlugin<TPlugin>()

注册一个第一方插件(Converter、DICOM)。采用流式 API——返回 options 实例。若缺少许可证、使用旧版 TRIAL 文件,或付费许可证未授予该插件功能,AddDoconut() 将抛出 InvalidOperationException。临时/演示注册在过期后仍会保留,并受运行时门控限制(参见核心概念 → 插件系统)。

可选的 Converter 小部件通过 AddConverterWidget() 启用,并通过只读的 ConverterWidget 属性暴露;其选项在 Converter 插件页面(插件 → Converter 插件)中有文档说明。

RegisterViewer(extension, factory, defaultConfig?)

text
DoconutOptions RegisterViewer(
    string extension,                    // ".myext" — leading dot optional
    Func<IFormatViewer> factory,
    Func<BaseConfig>? defaultConfig = null)

为文件扩展名注册一个 自定义查看器。自定义查看器优先于内置和插件查看器,且不受许可证限制。当省略 defaultConfig 且文档在未提供显式配置时,会使用 ImageConfig

若扩展名为空则抛出 ArgumentExceptionExtension must be a non-empty file extension.),若工厂为 null 则抛出 ArgumentNullException

启动验证

AddDoconut() 对选项进行 快速失败 验证,因此配置错误会在启动时抛出明确的异常,而不是在请求时出现令人困惑的 404。

text
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.

常见配置

csharp
// 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。

此页面有帮助吗?