Namespace
A Namespace in Postboy is a structured way to create and manage a scoped group of registrations through a registrator.
It is not just a naming layer over messages.
It is a convenience abstraction built on top of the Registrator lifecycle model.
That means a namespace in Postboy is created, activated, and destroyed through the same lifecycle rules as a registrator, and the client receives the registrator instance itself as the result of namespace creation.
What a Namespace is for
A namespace is useful when you want to:
scope a small group of messages to a parent feature or component
keep that scope isolated from the rest of the application
manage the lifecycle of those registrations together
avoid creating a dedicated Registrator class for a very small feature
keep message wiring close to the place where it is actually used
This is especially practical when the message set is small and does not justify a separate Registrator file or class hierarchy.
Why it matters
In small or medium-sized feature boundaries, the overhead of creating a separate Registrator class can be unnecessary.
For example:
a parent component may need a couple of messages to coordinate child components
those messages should exist only while the parent is alive
their subscriptions should disappear when the parent is destroyed
the developer wants lifecycle control, but without creating a standalone Registrator class
A namespace solves exactly this problem.
It gives you registrator-managed lifecycle control without forcing you to introduce a separate class just for a small scoped feature.
Namespace as a registrator shortcut
A namespace is best understood as a Registrator shortcut.
When you create a namespace, Postboy internally creates a Registrator and binds the namespace to that registrator’s lifecycle.
So instead of thinking about “namespace as a message bucket”, it is more accurate to think about it as:
This makes namespaces a lightweight option for:
small parent/child communication setups
feature-local bus wiring
temporary message scopes
scoped lifetime management
How Namespace works in Postboy
A namespace is created through a bus operation and returns a registrator instance.
That registrator can then be used to register messages, executors, handlers, or other scoped wiring.
The important part is that the namespace itself does not exist independently from the registrator lifecycle.
It is tied to it.
A simplified view looks like this:
When to use Namespace
Use a namespace when:
you need a short-lived message scope
the feature is small and local
the parent component owns the communication boundary
you want lifecycle management without creating a separate registrator class
you want to isolate messages for a limited part of the UI or module tree
When not to use Namespace
A namespace is probably not the right fit when:
the feature has complex startup/shutdown logic
the scope contains many related services
you need custom activation orchestration
the structure deserves its own explicit registrator class
In those cases, a dedicated registrator is clearer.
Namespace vs flat registration
A flat registration style can work for small experiments, but it becomes harder to maintain when scope matters.
Namespaces add:
lifecycle ownership
feature isolation
cleaner teardown
less accidental global coupling
That makes them a better fit for scoped communication.
In short
A Namespace in Postboy is a lightweight, scoped abstraction over a Registrator.
It is used when you need controlled message lifetime and feature isolation, but the scope is too small to justify a separate registrator class.