Disco - An container-Interop compatible DI container

Disco - An container-Interop compatible DI container

For years I speak at conferences about Dependency Injection. 5 years ago at pfCongres 2010, I started my speaking career with talking about Dependency Injection in the real world. Today, 5 years later am I am finally able to push our own implementation to Github. This is a completely different version compared to what I talked about 5 years ago but still it might be useful for some of you.

Kudos to Marco Pivetta and Mike van Riel for their insane work which builds the foundation of our current implementation.

This is how you use it:

composer.phar require bitexpert/disco

First, create a configuration class. The class needs to be marked with an @Configuration annotation. Add a public method for each instance you want to manage. The method name will be later used in the has() or get() method to retrieve the instance. Each method needs the @Bean annotation as well as the @return annotation.

use bitExpert\Disco\Annotations\Bean;
use bitExpert\Disco\Annotations\Configuration;
use bitExpert\Disco\Helper\SampleService;

 * @Configuration
class MyConfiguration
     * @Bean
     * @return SampleService
    public function mySampleService()
        return new SampleService();

To instantiate the \bitExpert\Disco\AnnotationBeanFactory proceed as follows:

$parameters = [];

$beanFactory = new \bitExpert\Disco\AnnotationBeanFactory(MyConfiguration::class, $parameters);

Since Disco implements the container-interop, you are able to call the has() and get() method as expected:



For more documentation check out the Disco Github repo or run the test suite :)

Eintrag von Stephan Hochdörfer am 04.11.2015

Tags: PHP, Disco, DI, Container-Interop

Diese Webseite verwendet Cookies, um die Bedienfreundlichkeit zu erhöhen. Mit der Nutzung unserer Webseite wird das Einverständnis erklärt, dass wir Cookies verwenden. Weitere Informationen.