Extend quickstart example with constructor injection

This commit is contained in:
Mike Bierlee 2016-09-03 18:19:38 +02:00
parent ea84198f3c
commit bfb23baf69
2 changed files with 22 additions and 2 deletions

View file

@ -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);

View file

@ -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);