I am creating an extension which will add a product to cart based on an url parameter (<https://unavio.de/shop/ExAddtoCart?sku=2889>). Code is running correct as long as I am not injecting any dependency other than:

```
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory

```

So here is my (working) Index.php:

```
<?php
namespace Unavio\ExternalAddToCart\Controller\Index;
use \Magento\Framework\App\Action\Action;

    class Index extends \Magento\Framework\App\Action\Action {
    protected $resultPageFactory;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    ) {
        $this->resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }

    public function execute() {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/AddToCart.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info("######### Start AddToCart call #########");
        $logger->info("Checking for URL-parameter");
        if (count($_GET) && isset($_GET['sku'])) {
            $sku = $_GET['sku'];
            $logger->info($sku);
            $params = array();
            $params['qty'] = '1';//product quantity

            ### Code should continue here :-)
        }else {
            $logger->info("No or invalidURL-parameter");
            return $this->resultRedirectFactory->create()->setPath('catalog/');
        } 
      }
    }

```

I am trying to follow this thread:

<https://stackoverflow.com/questions/38968822/add-product-to-cart-programatically-magento2>

But as soon as I inject

```
\Magento\Catalog\Model\Product $product,
\Magento\Checkout\Model\Cart $cart

```

like this:

```
<?php
namespace Unavio\ExternalAddToCart\Controller\Index;
use \Magento\Framework\App\Action\Action;
use \Magento\Catalog\Model\Product;
use \Magento\Checkout\Model\Cart;

class Index extends \Magento\Framework\App\Action\Action {
protected $cart;
protected $product;
protected $resultPageFactory;

public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\View\Result\PageFactory $resultPageFactory,
    \Magento\Catalog\Model\Product $product,
    \Magento\Checkout\Model\Cart $cart
) {
    $this->resultPageFactory = $resultPageFactory;
    $this->cart = $cart;
    $this->product = $product;
    parent::__construct($context);
}

public function execute() {
    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/AddToCart.log');
    $logger = new \Zend\Log\Logger();
    $logger->addWriter($writer);
    $logger->info("######### Start AddToCart call #########");
    $logger->info("Checking for URL-parameter");
    if (count($_GET) && isset($_GET['sku'])) {
        $sku = $_GET['sku'];
        $logger->info($sku);
        $params = array();
        $params['qty'] = '1';//product quantity
        $_product = $this->product->load($pId);
            if ($_product) {
                $this->cart->addProduct($_product, $params);
                $this->cart->save();
             }
        ### Code should continue here :-)
    }else {
        $logger->info("No or invalidURL-parameter");
        return $this->resultRedirectFactory->create()->setPath('catalog/');
    } 
  }
}

```

I am just getting a white page and no logging.
Any ideas what´s wrong with this?

Thank you :)