Hi I am looking to handle slim repository pattern in the common pattern
like:
productRepositoryInterface
productRepository
product
ProducCOntroller
How do I build that using dependency injection of SLIM
I have routing and it goes to the controller called ProductController
then in the controller, I want to get in the constructor the ProductRepo interface
my dependencies
$container['productController'] = function($c , ProductRepositoryInterface $productRepo) use ($app) {
return new ProductController($c ,$productRepo);
};
$container['productsRepository'] = function($c) use ($app) {
return new ProductRepository( $c->db );
};
but I Got in the controller constructor the following error:
Catchable fatal error: Argument 2 passed to ProductController::__construct() must be an instance of ProductRepositoryInterface, none given
Product controller:
function __construct($c,ProductRepositoryInterface $repo)
{
$this->c = $c;
// grab instance from container
$this->repository = $repo;
}