DoconutHost
System.Web에 대한 구성 루트
DoconutHost (네임스페이스 Doconut)는 전체 워커 프로세스에 대한 Doconut의 서비스를 소유하는 정적 클래스입니다. ASP.NET Core 애플리케이션은 이러한 서비스를 프레임워크 자체 컨테이너에 구축하지만, 클래식 ASP.NET에는 컨테이너가 없으므로 DoconutHost가 컨테이너를 만들고 유지합니다. DocImage.axd 핸들러와 리소스 모듈은 필요한 모든 것을 여기서 해결하며, 여러분의 코드도 마찬가지입니다.
| 멤버 | 목적 |
|---|---|
static void Initialize(Action<DoconutOptions>? configure = null, Action<IServiceCollection>? configureServices = null) | 서비스를 한 번만 구축합니다 |
static IServiceProvider Services { get; } | 구축된 컨테이너 |
static bool IsInitialized { get; } | Initialize가 실행된 후 true가 됩니다 |
static void Shutdown() | 백그라운드 작업을 중지하고 컨테이너를 해제합니다 |
Initialize
Global.asax.cs의 Application_Start에서 호출합니다:
// Global.asax.cs, Application_Start - once per worker process. A second call is a no-op:
// the first call's options win.
Doconut.DoconutHost.Initialize(
options =>
{
options.LicensePath = HostingEnvironment.MapPath("~/wwwroot/Doconut.Viewer.lic");
},
services =>
{
// Optional. Runs after Doconut's own registrations and before the container is built,
// so it can add services or replace one Doconut registered.
services.AddMemoryCache();
});- **
configure**는 DoconutOptions를 받습니다: 라이선스, 보안 스위치, 플러그인, 위젯. - **
configureServices**는 선택 사항입니다. Doconut 자체 등록이 완료되고 컨테이너가 구축되기 전에 실행되므로, 서비스를 추가하거나(AddDoconutDistributed는 웹 팜에서 일반적으로 사용됩니다) Doconut이 등록한 항목을 교체할 수 있습니다.
첫 번째 호출이 우선합니다. Initialize는 멱등합니다: 두 번째 호출은 즉시 반환하고, 그 위임자들은 실행되지 않습니다. 이는 중복된 Application_Start를 무해하게 만들지만, Initialize를 다시 호출하여 구성을 변경할 수 없으며 대신 애플리케이션 풀을 재시작해야 합니다.
여기서 발생하는 예외(라이선스가 없는 플러그인, 잘못된 옵션, 불완전한 팜 구성 등)는 Application_Start 내부에서 발생합니다. ASP.NET은 모든 요청에 빈 500 응답을 반환하고, 예외는 Windows 이벤트 로그(응용 프로그램 로그, 소스 ASP.NET)에만 기록됩니다.
서비스 및 IsInitialized
System.Web은 컨트롤러, 페이지, 핸들러에 대한 생성자 주입을 지원하지 않으므로, Doconut의 서비스를 사용하는 위치에서 직접 해결해야 합니다:
// System.Web has no constructor injection: resolve Doconut services where you use them.
var viewer = Doconut.DoconutHost.Services.GetRequiredService<Viewer>();
// Registered only when the Converter plugin is (see the plugin page).
var converter = Doconut.DoconutHost.Services.GetRequiredService<DocumentConverter>();Services는 Initialize 이전에 읽히면 InvalidOperationException(DoconutHost.Initialize must be called in Application_Start (Global.asax) before any Doconut request is served.)을 발생시킵니다. 더 일찍 실행될 수 있는 코드(모듈, 정적 생성자 등)는 먼저 IsInitialized를 확인할 수 있습니다.
코드에서 일반적으로 해결하는 서비스는 다음과 같습니다:
| 서비스 | 수명 | 역할 |
|---|---|---|
Viewer | Transient | 열기, 닫기, 주석, 리소스 도우미 — Viewer 참조 |
DocumentConverter | Transient | 변환 — Converter 플러그인과 함께 등록됩니다 |
IDoconutLicenseService | Singleton | 로드된 라이선스와 그 기능 — Licensing 참조 |
DoconutOptions | Singleton | Initialize에 전달된 옵션 |
HealthCheckService | Singleton | "doconut" 헬스 체크를 실행합니다 (아래). |
DoconutHost.Services에서 해결하고, 자체 컨테이너에서는 절대 해결하지 마세요. Doconut을 다른 컨테이너에 등록하면 핸들러와 모듈이 볼 수 없는 두 번째, 별도의 서비스 집합이 생성됩니다: 이를 통해 열린 문서는 DocImage.axd에서 알 수 없습니다.
종료
// Global.asax.cs, Application_End - stops background work and disposes the container.
// Safe to call twice, and safe when Initialize never ran.
Doconut.DoconutHost.Shutdown();Shutdown은 Doconut의 백그라운드 작업(분산 모드에서 사용)을 중지하고 컨테이너를 해제합니다. 두 번 호출해도 안전하며, Initialize가 실행되지 않은 경우에도 안전합니다 — 예를 들어 첫 요청 이전에 애플리케이션 풀이 재시작된 경우가 해당됩니다.
헬스 체크
Doconut은 라이선스 상태를 보고하는 "doconut"라는 헬스 체크를 등록합니다. 클래식 ASP.NET에는 자체 헬스 체크 엔드포인트가 없으므로, 컨트롤러에서 이를 노출합니다:
// GET /Health - Doconut registers a "doconut" health check that reports the license state:
// Healthy (valid), Degraded (trial or no license file), Unhealthy (expired).
public async Task<ActionResult> Index()
{
var health = Doconut.DoconutHost.Services.GetRequiredService<HealthCheckService>();
HealthReport report = await health.CheckHealthAsync();
Response.StatusCode = report.Status == HealthStatus.Unhealthy ? 503 : 200;
return Content(report.Status.ToString(), "text/plain");
}| 상태 | 의미 |
|---|---|
Healthy | 유효한 라이선스가 로드되었습니다 |
Degraded | 체험판이거나 라이선스 파일이 없습니다 |
Unhealthy | 라이선스가 만료되었습니다 |
ASP.NET Core 확장 메서드
이 패키지는 UseDoconut() 및 UseDoconutResources()를 포함하고 있으며, 이는 ASP.NET Core 파이프라인 확장 기능으로, ASP.NET Core 패키지와 코드를 공유하기 때문입니다. 이 패키지에서는 두 메서드 모두 [Obsolete]로 표시되어 사용되지 않습니다: System.Web 애플리케이션에는 추가할 요청 파이프라인이 없기 때문입니다. 대신 사용할 수 있는 것은 Installation에서 소개된 두 개의 Web.config 등록입니다:
| ASP.NET Core | .NET Framework 4.7.2 |
|---|---|
builder.Services.AddDoconut(...) | Application_Start에서 DoconutHost.Initialize(...) |
app.UseDoconut() | Web.config의 DocImage.axd에서 Doconut.DocImageHandler |
app.UseDoconutResources() | Web.config의 Doconut.DoconutResourceModule |
| Constructor injection | DoconutHost.Services.GetRequiredService<T>() |
| Host shutdown | Application_End에서 DoconutHost.Shutdown() |
이 페이지가 도움이 되었나요?