2017-02-13 20:20:35 +01:00
|
|
|
/**
|
|
|
|
* Poodinis Dependency Injection Framework
|
2023-01-11 00:01:51 +01:00
|
|
|
* Copyright 2014-2023 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;
|
|
|
|
|
2023-03-06 23:24:18 +01:00
|
|
|
interface Pie {
|
2023-05-17 23:03:02 +02:00
|
|
|
void eat();
|
2017-02-13 20:20:35 +01:00
|
|
|
}
|
|
|
|
|
2023-03-06 23:24:18 +01:00
|
|
|
class BlueBerryPie : Pie {
|
2023-05-17 23:03:02 +02:00
|
|
|
override void eat() {
|
2017-02-13 20:20:35 +01:00
|
|
|
writeln("Nom nom nom. I like this one!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-06 23:24:18 +01:00
|
|
|
class ApplePie : Pie {
|
2023-05-17 23:03:02 +02:00
|
|
|
override void eat() {
|
2017-02-13 20:20:35 +01:00
|
|
|
writeln("Nom nom nom. These aren't real apples...");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-06 23:24:18 +01:00
|
|
|
class CardboardBoxPie : Pie {
|
2023-05-17 23:03:02 +02:00
|
|
|
override void eat() {
|
2017-02-13 20:20:35 +01:00
|
|
|
writeln("Nom nom nom. This... is not a pie.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-06 23:24:18 +01:00
|
|
|
class PieEater {
|
2023-03-07 01:29:54 +01:00
|
|
|
@Inject private Pie[] pies;
|
2017-02-13 20:20:35 +01:00
|
|
|
|
2023-05-17 23:03:02 +02:00
|
|
|
void eatThemAll() {
|
2023-03-06 23:24:18 +01:00
|
|
|
foreach (pie; pies) {
|
2017-02-13 20:20:35 +01:00
|
|
|
pie.eat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-06 23:24:18 +01:00
|
|
|
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();
|
|
|
|
}
|