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 {
|
2017-02-13 20:20:35 +01:00
|
|
|
public void eat();
|
|
|
|
}
|
|
|
|
|
2023-03-06 23:24:18 +01:00
|
|
|
class BlueBerryPie : Pie {
|
|
|
|
public 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 {
|
|
|
|
public 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 {
|
|
|
|
public 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 {
|
2021-05-01 21:16:44 +02:00
|
|
|
@Autowire private Pie[] pies;
|
2017-02-13 20:20:35 +01:00
|
|
|
|
2023-03-06 23:24:18 +01:00
|
|
|
public void eatThemAll() {
|
|
|
|
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();
|
|
|
|
}
|