samedi 31 octobre 2015

What is the advantage of using constructor injection in a repository in laravel 5?

I am building a laravel 5 app and I have a repository like below:

use App\Unit

class UnitRepository implements IUnitRepository
{
     public function get_all_units()
    {
        return Unit::all();
    }

    // More methods below
}

In about 6 methods in the repository, I am doing something like Unit::someMethod. Now I am wondering if I should use constructor injection like so

class UnitRepository implements IUnitRepository
{
    public function __construct(Unit $unit){ 
        $this->unit = $unit
    }

    public function get_all_units()
    {
        return $this->unit->all();
    }

    // More methods below
}

So what would be the advantage of using constructor injection in my case. Is they some kind of performance improvement considering that I am using the facade in about 6 methods?

Appreciate help



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1P3S786
via IFTTT

Aucun commentaire:

Enregistrer un commentaire