poodinis/example/arraycompletion/app.d

54 lines
1.1 KiB
D
Raw Normal View History

2017-02-13 20:20:35 +01:00
/**
* Poodinis Dependency Injection Framework
2024-02-17 13:08:59 +01:00
* Copyright 2014-2024 Mike Bierlee
2017-02-13 20:20:35 +01:00
* 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 {
2017-02-13 20:20:35 +01:00
public void eat();
}
class BlueBerryPie : Pie {
public override void eat() {
2017-02-13 20:20:35 +01:00
writeln("Nom nom nom. I like this one!");
}
}
class ApplePie : Pie {
public override void eat() {
2017-02-13 20:20:35 +01:00
writeln("Nom nom nom. These aren't real apples...");
}
}
class CardboardBoxPie : Pie {
public override void eat() {
2017-02-13 20:20:35 +01:00
writeln("Nom nom nom. This... is not a pie.");
}
}
class PieEater {
@Inject private Pie[] pies;
2017-02-13 20:20:35 +01:00
public void eatThemAll() {
foreach (pie; pies) {
2017-02-13 20:20:35 +01:00
pie.eat();
}
}
}
void main() {
2017-02-13 20:20:35 +01:00
auto dependencies = new shared DependencyContainer();
dependencies.register!(Pie, BlueBerryPie);
dependencies.register!(Pie, ApplePie);
dependencies.register!(Pie, CardboardBoxPie);
dependencies.register!(PieEater);
auto eater = dependencies.resolve!PieEater;
eater.eatThemAll();
}