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 ```d
import poodinis; import poodinis;
class Driver {}
interface Database{}; 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 { class DataWriter {
@Autowire @Autowire
@ -43,6 +52,7 @@ class DataWriter {
void main() { void main() {
auto dependencies = new shared DependencyContainer(); auto dependencies = new shared DependencyContainer();
dependencies.register!Driver;
dependencies.register!DataWriter; dependencies.register!DataWriter;
dependencies.register!(Database, RelationalDatabase); dependencies.register!(Database, RelationalDatabase);

View file

@ -7,8 +7,17 @@
import poodinis; import poodinis;
class Driver {}
interface Database{}; 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 { class DataWriter {
@Autowire @Autowire
@ -17,6 +26,7 @@ class DataWriter {
void main() { void main() {
auto dependencies = new shared DependencyContainer(); auto dependencies = new shared DependencyContainer();
dependencies.register!Driver;
dependencies.register!DataWriter; dependencies.register!DataWriter;
dependencies.register!(Database, RelationalDatabase); dependencies.register!(Database, RelationalDatabase);