2017-02-13 20:20:35 +01:00
|
|
|
/**
|
|
|
|
* Poodinis Dependency Injection Framework
|
2021-01-04 00:04:20 +01:00
|
|
|
* Copyright 2014-2021 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;
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
class TownSquare
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
@Autowire private MarketStall marketStall;
|
2017-02-13 20:20:35 +01:00
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
public void makeSound()
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
marketStall.announceGoodsForSale();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
interface Goods
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
public string getGoodsName();
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
class Fish : Goods
|
|
|
|
{
|
|
|
|
public override string getGoodsName()
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
return "Fish";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
class MarketStall
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
private Goods goods;
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
this(Goods goods)
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
this.goods = goods;
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
public void announceGoodsForSale()
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
writeln(goods.getGoodsName() ~ " for sale!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
class ExampleApplicationContext : ApplicationContext
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
@Autowire private Goods goods;
|
2017-02-13 20:20:35 +01:00
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
public override void registerDependencies(shared(DependencyContainer) container)
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
container.register!(Goods, Fish);
|
|
|
|
container.register!TownSquare;
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
@Component public MarketStall marketStall()
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
return new MarketStall(goods);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
void main()
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.registerContext!ExampleApplicationContext;
|
|
|
|
|
|
|
|
auto townSquare = container.resolve!TownSquare;
|
|
|
|
townSquare.makeSound();
|
|
|
|
}
|