Add array completion example

This commit is contained in:
Mike Bierlee 2015-07-04 14:32:08 +02:00
parent e2b093785b
commit 9d5b4e97a7
3 changed files with 76 additions and 15 deletions

32
.gitignore vendored
View file

@ -1,16 +1,18 @@
/poodinis.exe /poodinis.exe
/poodinis.lib /poodinis.lib
/poodinis.obj /poodinis.obj
/quickstartExample.exe /quickstartExample.exe
/qualifiersExample.exe /qualifiersExample.exe
/.settings /arrayCompletionExample.exe
/.dub /.settings
/dub.selections.json /.dub
/docs /dub.selections.json
/__dummy.html /docs
/docs.json /__dummy.html
/poodinis /docs.json
/libpoodinis.a /poodinis
/.buildpath /libpoodinis.a
/quickstartExample /.buildpath
/quickstartExample
/qualifiersExample /qualifiersExample
/arrayCompletionExample

View file

@ -54,6 +54,18 @@
"importPaths": [ "importPaths": [
"source" "source"
] ]
},
{
"name" : "arrayCompletionExample",
"description" : "Example where an array is autowired with all registered instances.",
"targetType": "executable",
"targetName": "arrayCompletionExample",
"sourcePaths": [
"example/arraycompletion"
],
"importPaths": [
"source"
]
} }
] ]
} }

View 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();
}