---
title: DocumentBuildService
summary: API reference for DocumentBuildService.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# DocumentBuildService

Implements `IDocumentBuildService`, assembling the XML payload for a document request from its parameters and calling `IDocumentService.GeneratePdf` to produce the rendered PDF, while also marking the source request as complete via `IDocumentRequestService`. It is constructed with `IUnitOfWork`, `IUserProfileService`, and the `IDocumentRequestService`/`IDocumentParameterService` collaborators (the latter two exposed as protected settable properties).

## Purpose
- Converts a list of `DocumentRequestParameter` values into the XML document payload expected by the document-generation engine.
- Generates the final PDF for a document request, marking the request complete once parameters are consumed.
- Supports two hard-coded demo/example XML payloads (`HardCodedK2DemoXml`, `HardCodedCollectionsXml`) used by specific legacy templates.

## Context
- Namespace: `SAIF.Services.Documents`
- Assembly/package: `SAIF.Services` (packaged inside the `SAIF.SAIFCode.Core` NuGet package)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| DocumentBuildService(...) | `public DocumentBuildService(IUnitOfWork unitOfWork, IDocumentService documentService, Contract.IDocumentRequestService docRequestService, Contract.IDocumentParameterService docParameterService, IUserProfileService userProfileService)` | Stores the unit of work, document/request/parameter services, and user-profile collaborator, requiring non-null `unitOfWork` and `userProfileService`. |
| GetRequestedDocument(myRequest, documentParameters) | `public byte[] GetRequestedDocument(Contract.RequestLog myRequest, IList<Contract.DocumentRequestParameter> documentParameters)` | Builds the request XML from `documentParameters`, marks `myRequest` as complete via `RequestService`, and returns the generated PDF bytes for the request's template routine. |
| GetRequestedDocument(myRequest) | `public byte[] GetRequestedDocument(Contract.RequestLog myRequest)` | Selects one of two hard-coded demo XML payloads based on the request's `RunTemplate` name and returns the generated PDF bytes for the request's template routine. |

## Behavioral notes
- `GetRequestedDocument(myRequest, documentParameters)` skips any parameter whose `DataType` is `"SKIP"` when building the outgoing XML.
- The single-argument `GetRequestedDocument(myRequest)` overload only recognizes the `RunTemplate` values `"HardCodedCollectionsXml"` and `"HardCodedK2DemoXml"`; any other template value produces an empty XML payload*.
- The single-argument overload does not call `RequestService.SetRequestAsComplete` (that call is commented out), unlike the parameterized overload*.

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- Services/SAIF.Services/Documents/DocumentBuildService.cs
