From 9d5b4e97a789ac94954af056f06e84aefa485ac9 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Sat, 4 Jul 2015 14:32:08 +0200 Subject: [PATCH] Add array completion example --- .gitignore | 32 +++++++++++++----------- dub.json | 12 +++++++++ example/arraycompletion/app.d | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 example/arraycompletion/app.d diff --git a/.gitignore b/.gitignore index 7fedbd6..ff8263d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,18 @@ -/poodinis.exe -/poodinis.lib -/poodinis.obj -/quickstartExample.exe -/qualifiersExample.exe -/.settings -/.dub -/dub.selections.json -/docs -/__dummy.html -/docs.json -/poodinis -/libpoodinis.a -/.buildpath -/quickstartExample +/poodinis.exe +/poodinis.lib +/poodinis.obj +/quickstartExample.exe +/qualifiersExample.exe +/arrayCompletionExample.exe +/.settings +/.dub +/dub.selections.json +/docs +/__dummy.html +/docs.json +/poodinis +/libpoodinis.a +/.buildpath +/quickstartExample /qualifiersExample +/arrayCompletionExample diff --git a/dub.json b/dub.json index 93da84d..aedfa69 100644 --- a/dub.json +++ b/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" + ] } ] } diff --git a/example/arraycompletion/app.d b/example/arraycompletion/app.d new file mode 100644 index 0000000..31bbfda --- /dev/null +++ b/example/arraycompletion/app.d @@ -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(); +}