ProductServiceProvider.php
app/Providers/ProductServiceProvider.php
Service Provider for Product Domain
The ProductServiceProvider binds all product-related services, repositories, queries, and filters into the Laravel service container.
• Singleton bindings for stateless classes
• Dependency injection ready
• Centralized service registration
Complete Implementation
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use App\Repositories\ProductRepository; use App\Services\ProductService; use App\Queries\ProductQueries; use App\Filters\ProductFilter; use Illuminate\Http\Request; class ProductServiceProvider extends ServiceProvider { /** * Register any application services. * This method is where you bind classes into the service container. */ public function register(): void { // Bind ProductRepository as a singleton (optional, usually stateless repositories don't need this) $this->app->singleton(ProductRepository::class, function ($app) { return new ProductRepository(); }); // Bind ProductQueries as a singleton (recommended as it's stateless) $this->app->singleton(ProductQueries::class, function ($app) { return new ProductQueries(); }); // Bind ProductFilter as a singleton (recommended as it's stateless, and needs the current Request) $this->app->singleton(ProductFilter::class, function ($app) { return new ProductFilter($app->make(Request::class)); }); // Bind ProductService (usually not a singleton, unless its state needs to be shared) $this->app->singleton(ProductService::class, function ($app) { return new ProductService( $app->make(ProductRepository::class), $app->make(ProductQueries::class) ); }); } /** * Bootstrap any application services. * This method is where you can perform actions after all services are registered. */ public function boot(): void { // } }
💡
Key Features
• Singleton bindings for stateless services
• Dependency injection for all product domain classes
• Centralized and maintainable service registration