- Home
- /
- Foundation
- /
- DMBPageBuilder
- /
- Builder lifecycle
Builder Lifecycle
Understand when a builder starts, writes, and completes its output.
Overview
The builder lifecycle is one of the central concepts of PageBuilder. A builder is not just a passive wrapper around HTML. It participates in a rendering process with a defined beginning, an output phase, and a completion phase.
This lifecycle is what makes builders reusable, composable, and predictable inside the PageBuilder rendering pipeline.
Lifecycle diagram
The diagram shows the two rendering styles that PageBuilder builders commonly use: scoped rendering with Begin() and Dispose() , and page model enrichment during rendering.
Why lifecycle matters
Without a clear lifecycle, a rendering system quickly becomes difficult to reason about. Components start writing output at arbitrary times, nested rendering becomes fragile, and debugging rendering order becomes harder.
PageBuilder avoids this by giving builders a disciplined rendering model. This model allows a builder to behave consistently whether it is used in Razor, in C#, or inside a larger builder composition.
The core rendering contract
At the lowest level, builders render themselves through WriteTo(...) . This is the base output contract used by the framework. WriteTo(...) is responsible for:
This means builders do not generally write their output by directly assembling arbitrary strings from outside the lifecycle. They render themselves through the framework contract.
Begin and Dispose
Some builders represent a structural region rather than a single atomic element. In those cases, the most natural rendering pattern is a scoped lifecycle based on Begin() and Dispose() . This pattern is used when a builder needs to:
Using blocks
This makes builders fit naturally inside using blocks. Begin() writes the opening structure, nested content is rendered, then Dispose() writes the closing structure. This is especially useful for container-like builders and region builders.
Render and WriteTo
Not every builder needs a scoped lifecycle. Some builders are atomic and can render themselves in a single step. In those cases, Render() or WriteTo(...) is often sufficient.
Lifecycle and nesting
The builder lifecycle is especially important when builders are nested. A parent builder may open a region, a child builder may render inside it, and both must still produce correct and predictable output. A consistent lifecycle ensures that:
Lifecycle and PageInformation
A builder does not only generate visible HTML. During its lifecycle, it may also enrich the shared PageInformation instance used by the rendering pipeline. For example, a builder may register:
This means the lifecycle of a builder is not limited to writing markup. It can also contribute to the final document model while it renders.
Recommended usage
Continue with BodyBuilder
Learn how BodyBuilder controls the body shell within the pipeline.
Layout & BodyBuilder →