mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add array completion example
This commit is contained in:
parent
e2b093785b
commit
9d5b4e97a7
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,6 +3,7 @@
|
|||
/poodinis.obj
|
||||
/quickstartExample.exe
|
||||
/qualifiersExample.exe
|
||||
/arrayCompletionExample.exe
|
||||
/.settings
|
||||
/.dub
|
||||
/dub.selections.json
|
||||
|
@ -14,3 +15,4 @@
|
|||
/.buildpath
|
||||
/quickstartExample
|
||||
/qualifiersExample
|
||||
/arrayCompletionExample
|
||||
|
|
12
dub.json
12
dub.json
|
@ -54,6 +54,18 @@
|
|||
"importPaths": [
|
||||
"source"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "arrayCompletionExample",
|
||||
"description" : "Example where an array is autowired with all registered instances.",
|
||||
"targetType": "executable",
|
||||
"targetName": "arrayCompletionExample",
|
||||
"sourcePaths": [
|
||||
"example/arraycompletion"
|
||||
],
|
||||
"importPaths": [
|
||||
"source"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
47
example/arraycompletion/app.d
Normal file
47
example/arraycompletion/app.d
Normal file
|
@ -0,0 +1,47 @@
|
|||
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
|
||||
public Pie[] pies;
|
||||
|
||||
public void eatThemAll() {
|
||||
foreach(pie ; pies) {
|
||||
pie.eat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto dependencies = DependencyContainer.getInstance();
|
||||
dependencies.register!(Pie, BlueBerryPie);
|
||||
dependencies.register!(Pie, ApplePie);
|
||||
dependencies.register!(Pie, CardboardBoxPie);
|
||||
dependencies.register!(PieEater);
|
||||
|
||||
auto eater = dependencies.resolve!PieEater;
|
||||
eater.eatThemAll();
|
||||
}
|
Loading…
Reference in a new issue