mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Extend quickstart example with constructor injection
This commit is contained in:
parent
ea84198f3c
commit
bfb23baf69
12
README.md
12
README.md
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue