Use dependency injection to get rid of the RecipeService Constructor

That makes it easier to test.
This commit is contained in:
Daniel Röhrig 2019-10-21 22:00:17 +02:00
Родитель 5658e3b1c8
Коммит f044df745e
3 изменённых файлов: 6 добавлений и 9 удалений

Просмотреть файл

@ -13,16 +13,14 @@ use OCA\Cookbook\Service\RecipeService;
class PageController extends Controller
{
private $userId;
private $service;
private $urlGenerator;
public function __construct($AppName, IDBConnection $db, IRootFolder $root, IRequest $request, $UserId, IConfig $config, IURLGenerator $urlGenerator)
public function __construct($AppName, IRequest $request, RecipeService $recipeService, IURLGenerator $urlGenerator)
{
parent::__construct($AppName, $request);
$this->userId = $UserId;
$this->service = new RecipeService($root, $UserId, $db, $config);
$this->service = $recipeService;
$this->urlGenerator = $urlGenerator;
}

Просмотреть файл

@ -26,12 +26,11 @@ class RecipeController extends Controller
*/
private $urlGenerator;
public function __construct($AppName, IDBConnection $db, IRootFolder $root, IRequest $request, IConfig $config, $UserId, IURLGenerator $urlGenerator)
public function __construct($AppName, IRequest $request, IURLGenerator $urlGenerator, RecipeService $recipeService)
{
parent::__construct($AppName, $request);
$this->userId = $UserId;
$this->service = new RecipeService($root, $UserId, $db, $config);
$this->service = $recipeService;
$this->urlGenerator = $urlGenerator;
}

Просмотреть файл

@ -18,8 +18,8 @@ class RecipeService {
private $db;
private $config;
public function __construct($root, $userId, IDBConnection $db, IConfig $config) {
$this->userId = $userId;
public function __construct($UserId, IRootFolder $root, IDBConnection $db, IConfig $config) {
$this->userId = $UserId;
$this->root = $root;
$this->db = new RecipeDb($db);
$this->config = $config;