www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - dmocks 0.91; dconstructor 0.9

First, dmocks has advanced to version 0.91 and merely needs testing to 
reach a 1.0 release. It's still only D2/phobos. Get it while it's hot:
download:
http://dsource.org/projects/dmocks/browser/downloads/dmocks.0.91.zip?format=raw

wiki:
http://dsource.org/projects/dmocks/wiki


Second, I'm proud[1] to announce a lightweight dependency injection 
framework, dconstructor. It's modeled after Google Guice, with the 
failing that D doesn't have attributes at present, so all configuration 
has to use the builder directly.

Dconstructor supports D1 and D2, Phobos and Tango. (Tested with 
D2/Phobos, D1/Tango.) It's under the BSD license.

download:
http://dsource.org/projects/dmocks/browser/downloads/dconstructor.0.9.zip?format=raw

wiki:
http://dsource.org/projects/dmocks/wiki/DConstructor

Example usage:
---
import dconstructor.build;
import dconstructor.singleton;

interface IFoo {}

class Foo : IFoo {}

// By implementing the Singleton interface, it's automatically
// a singleton.
class Bar : Singleton {
    this (IFoo foo) {}
}

void main () {
    builder.bind!(IFoo, Foo);

    // All my dependencies are built for me (take that, CAB!):
    auto bar1 = builder.get!(Bar);
    auto bar2 = builder.get!(Bar);
    assert (bar1 is bar2);

    // I can build stuff on my own, too, and have dconstructor
    // use that:
    auto foo = new Foo();
    builder.provide!(IFoo)(foo);
    assert (builder.get!(IFoo) is foo);

    // I registered it for IFoo, but not for Foo, though:
    assert (builder.get!(Foo) !is foo);
}
---


[1]I'm proud, I say. Proud! Putting on airs and strutting like a peacock.
Nov 29 2007