2016-01-06 20:28:25 +01:00
|
|
|
/**
|
|
|
|
* Poodinis Dependency Injection Framework
|
|
|
|
* Copyright 2014-2016 Mike Bierlee
|
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* The full terms of the license can be found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import poodinis;
|
|
|
|
|
|
|
|
import std.stdio;
|
|
|
|
|
|
|
|
interface Pie {
|
|
|
|
public void eat();
|
|
|
|
}
|
|
|
|
|
|
|
|
class BlueBerryPie : Pie {
|
|
|
|
public override void eat() {
|
|
|
|
writeln("Nom nom nom. I like this one!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ApplePie : Pie {
|
|
|
|
public override void eat() {
|
|
|
|
writeln("Nom nom nom. These aren't real apples...");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CardboardBoxPie : Pie {
|
|
|
|
public override void eat() {
|
|
|
|
writeln("Nom nom nom. This... is not a pie.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class PieEater {
|
|
|
|
@Autowire
|
2016-02-09 21:06:07 +01:00
|
|
|
private Pie[] pies;
|
2016-01-06 20:28:25 +01:00
|
|
|
|
|
|
|
public void eatThemAll() {
|
|
|
|
foreach(pie ; pies) {
|
|
|
|
pie.eat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
2016-08-08 22:17:17 +02:00
|
|
|
auto dependencies = new shared DependencyContainer();
|
2016-01-06 20:28:25 +01:00
|
|
|
dependencies.register!(Pie, BlueBerryPie);
|
|
|
|
dependencies.register!(Pie, ApplePie);
|
|
|
|
dependencies.register!(Pie, CardboardBoxPie);
|
|
|
|
dependencies.register!(PieEater);
|
|
|
|
|
|
|
|
auto eater = dependencies.resolve!PieEater;
|
|
|
|
eater.eatThemAll();
|
|
|
|
}
|