elkarte / Elkarte

ElkArte Forum. A free, open source, modern discussion forum / BB
https://elkarte.github.io/Elkarte/
BSD 3-Clause "New" or "Revised" License
175 stars 61 forks source link

Dependency injection #2629

Open live627 opened 8 years ago

live627 commented 8 years ago

I want to implement a dependency injector into Elk. I was thinking on Simplex, which is a Pimple 3 fork with full container-interop compliance and cross-framework service-provider support.

Example implantation:

use Interop\Container\ServiceProvider as s;
use Interop\Container\ContainerInterface;

class ServiceProvider implements s
{
    public function getServices()
    {
        return [
            'httpreq' => function(ContainerInterface $container, callable $getPrevious = null) {
                $dependency = $container->get('datavalidator');
                return new HttpReq($dependency);
            },
            'eventmanager' => function(ContainerInterface $container, callable $getPrevious = null) {
                return new EventManager;
            }
        ];
    }
}

All singletons can be converted back to real instantiable objects and included in the container. Instead of random objects passed to all controllers, just the container goes.

Spuds commented 8 years ago

nods we do need a DIC, I know there was a discussion about this somewhere, I think @joshuaadickerson had some ideas about this as well.

I'm not sure when its right to add this ... 1.1, 2.0 ... maybe 1.2 if we go that route, not sure.

Anyway its great idea, I need to read up more about this library to get me some educated bout it.