Helper :-
<?php
namespace MageplazaHelloWorldHelper;
use MagentoFrameworkAppHelperAbstractHelper;
class Data extends AbstractHelper
{
public function getStoreConfig()
{
echo 'This is Dependency Injection';
}
}
Controller:-
<?php
namespace MageplazaHelloWorldControllerDependency;
use MageplazaHelloWorldHelperData;
use MagentoFrameworkAppActionAction;
use MagentoFrameworkAppActionInterface;
class Dependency extends MagentoFrameworkAppActionAction
{
public function __construct(Data $helper)
{
$this->helper = $helper;
}
public function execute()
{
$this->helper->getStoreConfig();
exit();
}
}