November 02, 2014
On Saturday, 1 November 2014 at 19:19:51 UTC, JN wrote:
> But then you have to pass the container around? Or you make it a singleton?

Basically yes.
November 19, 2014
On Friday, 17 October 2014 at 22:55:24 UTC, Orfeo wrote:
> Hi all,
>
> I'd like to announce the initial version of endovena, a dependency injection
> framework.
>
> It's based on dejector, a great work by Jakub Stasiak, with some new features borrowed from dryioc (C# IoC)
>
> I would be glad to see any feedback,
> Thank you.
>
> * [endovena] https://github.com/o3o/endovena Boost License 1.0
> * [dejector](https://github.com/jstasiak/dejector)
> * [dryioc](https://bitbucket.org/dadhi/dryioc)

Am I missing something or is this a Service Locator anti-pattern? More about it here: http://blog.ploeh.dk/2010/02/03/ServiceLocatorisanAnti-Pattern/
November 19, 2014
> Am I missing something or is this a Service Locator anti-pattern? More about it here: http://blog.ploeh.dk/2010/02/03/ServiceLocatorisanAnti-Pattern/

Service Locator is *really* an anti-pattern, but endovena (and also dejector) is a Dependency Injector (DI) framework, opposite of Service locator (http://www.infoq.com/articles/Succeeding-Dependency-Injection)
DI is the solution to the principle of Inversion of Control (IoC), and DI Framework is a Framework (!) that help you to implement DI.

So, using Mark Seemann example:

```C#
public class OrderProcessor : IOrderProcessor
{
    public void Process(Order order)
    {
        var validator = Locator.Resolve<IOrderValidator>();
        if (validator.Validate(order))
        {
            var shipper = Locator.Resolve<IOrderShipper>();
            shipper.Ship(order);
        }
    }
}
```

Using DI you should write:

```D
class OrderProcessor : IOrderProcessor {
    private IOrderValidator validator;
    this(IOrderValidator validator, IOrderShipper shipper) {
      assert(validator !is null);
      this.validator = validator;
      this.shipper = shipper;
    }

    void Process(Order order) {
        if (validator.Validate(order))   {
            shipper.Ship(order);
        }
    }
}
```
in this version of OrderProcessor there is no Locator: the dependencies (IOrderValidator and IOrderShipper) are passed through constructor.

But... where is DI framework?


Endovena helps you to inject service into clients:

```D
import endovena;

void main() {
   Container container = new Container;
   container.register!(IOrderValidator,OrderValidator);
   container.register!(IOrderShipper,OrderShipper);
   container.register!(IOrderProcessor,OrderProcessor);

   auto processor = container.get!IOrderProcessor();

   processor.Process(order);
}

```


DI isn't easyto understand, but it's a very powerful pattern.

Some links:

* http://www.theserverside.com/news/1321158/A-beginners-guide-to-Dependency-Injection
* http://geekswithblogs.net/chrisfalter/archive/2008/02/15/new-statement-considered-harmful.aspx
* http://comoyo.github.io/blog/2013/02/06/the-inverse-of-ioc-is-control/
* http://www.loosecouplings.com/2011/01/dependency-injection-using-di-container.html
1 2
Next ›   Last »