I have a TransportationController which uses six repositories. The repositories are injected to the controller via constructor and method.
TransportationController.php
use Illuminate\Http\Request;
use App\Repositories\TransportationRepository;
use App\Repositories\TruckRepository;
use App\Repositories\AccountRepository;
use App\Repositories\SiteRepository;
use App\Repositories\EmployeeRepository;
use App\Repositories\EmployeeWageRepository;
use App\Http\Requests\TransportationRegistrationRequest;
use App\Http\Requests\TransportationFilterRequest;
use \Carbon\Carbon;
class TransportationController extends Controller
{
protected $transportationRepo;
public $errorHead = 5, $noOfRecordsPerPage = 15;
public function __construct(TransportationRepository $transportationRepo)
{
$this->transportationRepo = $transportationRepo;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(TransportationFilterRequest $request, TruckRepository $truckRepo, AccountRepository $accountRepo, SiteRepository $siteRpepo, EmployeeRepository $employeeRepo)
{
//some filtering stuff
$transportations = $this->transportationRepo->getTransportations($params, $noOfRecords);
return view('transportations.list', [
'accounts' => $accountRepo->getAccounts(),
'sites' => $siteRpepo->getSites(),
'trucks' => $truckRepo->getTrucks(),
'drivers' => $employeeRepo->getEmployees(),
'materials' => $this->transportationRepo->getMaterials(),
'transportations' => $transportations,
'rentTypes' => $this->transportationRepo->rentTypes,
'params' => $params,
'noOfRecords' => $noOfRecords,
]);
}
}
- Is there any architecture faults in injecting many(about 5 or 6) repositories to a controller?
- Is there any performance issue related to injecting many(about 5 or 6) repositories to a controller?
- What are the difference in injecting repositories through constructor vs injecting through method?
- What about injecting repositories in another repositories