2017-02-13 20:20:35 +01:00
|
|
|
/**
|
|
|
|
* Poodinis Dependency Injection Framework
|
2019-07-14 11:40:16 +02:00
|
|
|
* Copyright 2014-2019 Mike Bierlee
|
2017-02-13 20:20:35 +01:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* The full terms of the license can be found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import poodinis;
|
|
|
|
|
|
|
|
import std.stdio;
|
|
|
|
|
|
|
|
class TownSquare {
|
|
|
|
|
|
|
|
@Autowire
|
|
|
|
private 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
|
|
|
|
private 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 = new shared DependencyContainer();
|
|
|
|
container.registerContext!ExampleApplicationContext;
|
|
|
|
|
|
|
|
auto townSquare = container.resolve!TownSquare;
|
|
|
|
townSquare.makeSound();
|
|
|
|
}
|