Mahdee Rajon  subception

File "CqrsServiceProvider.php"

Full Path: /var/www/html/back/app/Providers/CqrsServiceProvider.php
File size: 1.19 KB
MIME-type: text/x-php
Charset: utf-8

<?php

declare(strict_types=1);

namespace App\Providers;

use App\Buses\CommandBus;
use App\Buses\QueryBus;
use App\Contracts\CommandBusContract;
use App\Contracts\QueryBusContract;
use App\Domain\Object\Handlers\Read\GetAllPaymentsQueryHandler;
use App\Domain\Object\Handlers\Read\GetPaymentByIdQueryHandler;
use App\Domain\Payment\Queries\GetAllPaymentsQuery;
use App\Domain\Payment\Queries\GetPaymentByIdQuery;
use Illuminate\Support\ServiceProvider;

final class CqrsServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        $this->app->singleton(
            abstract: CommandBusContract::class,
            concrete: CommandBus::class
        );

        $this->app->singleton(
            abstract: QueryBusContract::class,
            concrete: QueryBus::class
        );
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        app(abstract: QueryBusContract::class)->register(map: [
            GetAllPaymentsQuery::class => GetAllPaymentsQueryHandler::class,
            GetPaymentByIdQuery::class => GetPaymentByIdQueryHandler::class,
        ]);
    }
}