mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add application context example
This commit is contained in:
parent
78e8acd7a3
commit
435dc37c3c
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -1,10 +1,6 @@
|
||||||
/poodinis.exe
|
/*.exe
|
||||||
/poodinis.lib
|
/poodinis.lib
|
||||||
/poodinis.obj
|
/poodinis.obj
|
||||||
/quickstartExample.exe
|
|
||||||
/qualifiersExample.exe
|
|
||||||
/arrayCompletionExample.exe
|
|
||||||
/annotationsExample.exe
|
|
||||||
/.settings
|
/.settings
|
||||||
/.dub
|
/.dub
|
||||||
/dub.selections.json
|
/dub.selections.json
|
||||||
|
@ -18,3 +14,4 @@
|
||||||
/qualifiersExample
|
/qualifiersExample
|
||||||
/arrayCompletionExample
|
/arrayCompletionExample
|
||||||
/annotationsExample
|
/annotationsExample
|
||||||
|
/applicationContextExample
|
||||||
|
|
|
@ -11,4 +11,5 @@ script:
|
||||||
- dub build --build=release --config=qualifiersExample
|
- dub build --build=release --config=qualifiersExample
|
||||||
- dub build --build=release --config=arrayCompletionExample
|
- dub build --build=release --config=arrayCompletionExample
|
||||||
- dub build --build=release --config=annotationsExample
|
- dub build --build=release --config=annotationsExample
|
||||||
|
- dub build --build=release --config=applicationContextExample
|
||||||
# - dub build --build=ddox
|
# - dub build --build=ddox
|
||||||
|
|
12
dub.json
12
dub.json
|
@ -78,6 +78,18 @@
|
||||||
"importPaths": [
|
"importPaths": [
|
||||||
"source"
|
"source"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "applicationContextExample",
|
||||||
|
"description" : "Example where an application context is used to set-up dependencies.",
|
||||||
|
"targetType": "executable",
|
||||||
|
"targetName": "applicationContextExample",
|
||||||
|
"sourcePaths": [
|
||||||
|
"example/applicationcontext"
|
||||||
|
],
|
||||||
|
"importPaths": [
|
||||||
|
"source"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
61
example/applicationcontext/app.d
Normal file
61
example/applicationcontext/app.d
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
import poodinis;
|
||||||
|
|
||||||
|
import std.stdio;
|
||||||
|
|
||||||
|
class TownSquare {
|
||||||
|
|
||||||
|
@Autowire
|
||||||
|
public MarketStall marketStall;
|
||||||
|
|
||||||
|
public void makeSound() {
|
||||||
|
marketStall.announceGoodsForSale();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Goods {
|
||||||
|
public string getGoodsName();
|
||||||
|
}
|
||||||
|
|
||||||
|
class Fish : Goods {
|
||||||
|
public override string getGoodsName() {
|
||||||
|
return "Fish";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MarketStall {
|
||||||
|
private Goods goods;
|
||||||
|
|
||||||
|
this(Goods goods) {
|
||||||
|
this.goods = goods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void announceGoodsForSale() {
|
||||||
|
writeln(goods.getGoodsName() ~ " for sale!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExampleApplicationContext : ApplicationContext {
|
||||||
|
|
||||||
|
@Autowire
|
||||||
|
public Goods goods;
|
||||||
|
|
||||||
|
public override void registerDependencies(shared(DependencyContainer) container) {
|
||||||
|
container.register!(Goods, Fish);
|
||||||
|
container.register!TownSquare;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public MarketStall marketStall() {
|
||||||
|
return new MarketStall(goods);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
auto container = DependencyContainer.getInstance();
|
||||||
|
container.registerContext!ExampleApplicationContext;
|
||||||
|
|
||||||
|
auto townSquare = container.resolve!TownSquare;
|
||||||
|
townSquare.makeSound();
|
||||||
|
}
|
Loading…
Reference in a new issue