Core Setup
The Core Setup is the foundational step in any DomusJS application.
It ensures that all core services, buses, and dependencies are correctly initialized before other modules or bounded contexts are registered.
✅ DomusJS provides the helper function registerDomusCore()
to simplify this process.
registerDomusCore
Section titled “registerDomusCore”The registerDomusCore()
function sets up:
- The Command Bus (default:
InMemoryCommandBus
). - The Query Bus (default:
InMemoryQueryBus
). - The Event Bus (default:
InMemoryEventBus
). - The Logger (default or custom).
- Core middlewares or hooks.
It ensures that:
- Buses are registered once and centrally.
- Other modules can safely resolve
CommandBus
,QueryBus
,EventBus
, orLogger
from the DI container.
Example Setup
Section titled “Example Setup”import { registerDomusCore } from '@domusjs/infrastructure';import { PinoLogger } from '@domusjs/infrastructure';
registerDomusCore({});
✅ This must be called before registering any other dependencies or bounded contexts.
Why Order Matters
Section titled “Why Order Matters”Since many parts of your app will depend on the buses (CommandBus
, QueryBus
, EventBus
),
you need to ensure they are initialized first, so later modules can attach handlers or middleware safely.
Best Practices
Section titled “Best Practices”- Always call
registerDomusCore()
at the very beginning of your app bootstrap. - If you replace the buses (e.g., using RabbitMQ or Google Pub/Sub),
pass them explicitly into the setup function or register them immediately after. - Avoid re-registering the same core services elsewhere.