Skip to content

Domain Communication Patterns

Use events for loose coupling between domains:

php
// Vendor domain dispatches event
event(new VendorApproved($vendor));

// Communications domain listens
class SendVendorApprovalEmail
{
    public function handle(VendorApproved $event): void
    {
        // Send email notification
    }
}

2. Service Contracts

Define interfaces for cross-domain dependencies:

php
// Shared contract
interface PaymentProcessorInterface
{
    public function charge(int $amount, string $customerId): PaymentResult;
}

// Payments domain implements
class StripePaymentProcessor implements PaymentProcessorInterface
{
    public function charge(int $amount, string $customerId): PaymentResult
    {
        // Implementation
    }
}

3. Domain Services

For direct domain interaction when necessary:

php
// Use dependency injection
class BookingService
{
    public function __construct(
        private readonly VendorService $vendorService,
        private readonly PaymentService $paymentService
    ) {}

    public function createBooking(array $data): Booking
    {
        $vendor = $this->vendorService->find($data['vendor_id']);
        $payment = $this->paymentService->charge($data['amount']);

        // Create booking
    }
}

Wedissimo API Documentation