Register a Provider for it's TypeInfo. A name can also be provided to disambiguate when multiple providers are needed
Register a single value.
Register a Class.
Register a factory function for a type.
Register a provider using the type returned by provider.providedType.
import injected.injection; @Injectable!(int, Injected!(int, "a")) static class A { int x; int y; this(int x, int y) { this.x = x; this.y = y; } } static class B : A { string name; this(int x, int y, string name) { super(x, y); this.name = name; } } static struct C { string name; ushort id; static ushort idCounter = 0; } static C makeC() { return C("Foo", C.idCounter++); } auto container = makeContainer(); container.value!int(0); container.value!int("a", 1); container.register!A(); container.register!(A, B)("b"); container.factory!string(delegate(C c) { return c.name; }); container.factory!(C, makeC)(); container.factory!(C, makeC)("c", No.asSingleton); assert(container.resolve!int() == 0); assert(container.resolve!int("a") == 1); assert(container.resolve!string() == "Foo"); auto a = container.resolve!A(); assert(a.x == 0); assert(a.y == 1); auto b = cast(B) container.resolve!A("b"); assert(b); assert(b.x == 0); assert(b.y == 0); assert(b.name == "Foo"); assert(container.resolve!C().id == 0); auto c = container.resolve!C("c"); assert(c.name == "Foo"); assert(c.id == 1); assert(container.resolve!C("c").id == 2);
A simple implementation of Container.
SimpleContainer stores providers keyed by the TypeInfo and name, in that order. The container itself is registered, so that it can be injected as a dependency into other objects.