Direct Mode (Use Case)
Direct Mode uses a simpler pattern where controllers directly invoke Use Cases. This mode is suitable for straightforward operations without complex business logic, providing faster implementation and reduced boilerplate.
Use Cases
Use Cases encapsulate application logic with explicit Request/Response objects. They have a single responsibility per operation and are invoked directly without a bus.
Flow Example
From the demo application (Homepage module):
// Controller invokes use case directly
$response = $this->useCase->execute(new HomeRequest());
$viewModel = $this->presenter->present($response)->getViewModel();
Comparison with Bus Mode
| Aspect | Direct Mode | Bus Mode |
|---|---|---|
| Invocation | $useCase->execute($req) | $bus->dispatch($cmd) |
| Return Value | Returns Response | Commands void, Queries Response |
| Events | Manual | Automatic |
| Transactions | Manual | Automatic |
| Middleware | No | Yes |
| Boilerplate | Less | More |
Benefits
Direct Mode offers simplicity with no buses to configure, direct method calls, and easier comprehension. Development speed improves with less boilerplate and faster prototyping.
Limitations
Events and transactions must be handled manually. Cross-cutting concerns require explicit implementation.
When to Use
Direct Mode is recommended for:
- Simple CRUD operations
- Read-only queries without business logic
- Rapid prototyping
- Operations without domain events
In the demo application, the Homepage module uses Direct Mode.
See Also
- Use Cases - UseCase pattern implementation
- Homepage Module - Direct Mode in practice