From bfb23baf696cf753363c5d8e47534de8d5a3d5e3 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Sat, 3 Sep 2016 18:19:38 +0200 Subject: [PATCH] Extend quickstart example with constructor injection --- README.md | 12 +++++++++++- example/quickstart/app.d | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 52c2829..a7f5c40 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,17 @@ The following example shows the typical usage of Poodinis: ```d import poodinis; +class Driver {} + interface Database{}; -class RelationalDatabase : Database {} + +class RelationalDatabase : Database { + private Driver driver; + + this(Driver driver) { // Automatically injected on creation by container + this.driver = driver; + } +} class DataWriter { @Autowire @@ -43,6 +52,7 @@ class DataWriter { void main() { auto dependencies = new shared DependencyContainer(); + dependencies.register!Driver; dependencies.register!DataWriter; dependencies.register!(Database, RelationalDatabase); diff --git a/example/quickstart/app.d b/example/quickstart/app.d index 02d3823..b5d21ab 100644 --- a/example/quickstart/app.d +++ b/example/quickstart/app.d @@ -7,8 +7,17 @@ import poodinis; +class Driver {} + interface Database{}; -class RelationalDatabase : Database {} + +class RelationalDatabase : Database { + private Driver driver; + + this(Driver driver) { // Automatically injected on creation by container + this.driver = driver; + } +} class DataWriter { @Autowire @@ -17,6 +26,7 @@ class DataWriter { void main() { auto dependencies = new shared DependencyContainer(); + dependencies.register!Driver; dependencies.register!DataWriter; dependencies.register!(Database, RelationalDatabase);