2017-02-13 20:20:35 +01:00
|
|
|
/**
|
|
|
|
* Poodinis Dependency Injection Framework
|
2023-01-11 00:01:51 +01:00
|
|
|
* Copyright 2014-2023 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.
|
|
|
|
*/
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
import std.stdio;
|
2021-04-28 23:30:12 +02:00
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
class Scheduler
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
private Calendar calendar;
|
|
|
|
|
|
|
|
// All parameters will autmatically be assigned when Scheduler is created.
|
2021-05-01 21:16:44 +02:00
|
|
|
this(Calendar calendar)
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
this.calendar = calendar;
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
public void scheduleJob()
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
calendar.findOpenDate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
class Calendar
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
private HardwareClock hardwareClock;
|
|
|
|
|
|
|
|
// This constructor contains built-in type "int" and thus will not be used.
|
2021-05-01 21:16:44 +02:00
|
|
|
this(int initialDateTimeStamp, HardwareClock hardwareClock)
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// This constructor is chosen instead as candidate for injection when Calendar is created.
|
2021-05-01 21:16:44 +02:00
|
|
|
this(HardwareClock hardwareClock)
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
this.hardwareClock = hardwareClock;
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
public void findOpenDate()
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
hardwareClock.doThings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
class HardwareClock
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
// Parameterless constructors will halt any further selection of constructors.
|
2021-05-01 21:16:44 +02:00
|
|
|
this()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-13 20:20:35 +01:00
|
|
|
// As a result, this constructor will not be used when HardwareClock is created.
|
2021-05-01 21:16:44 +02:00
|
|
|
this(Calendar calendar)
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
throw new Exception("This constructor should not be used by Poodinis");
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
public void doThings()
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
writeln("Things are being done!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
void main()
|
|
|
|
{
|
2017-02-13 20:20:35 +01:00
|
|
|
import poodinis; // Locally imported to emphasize that classes do not depend on Poodinis.
|
|
|
|
|
|
|
|
auto dependencies = new shared DependencyContainer();
|
|
|
|
dependencies.register!Scheduler;
|
|
|
|
dependencies.register!Calendar;
|
2021-04-28 23:30:12 +02:00
|
|
|
dependencies.register!HardwareClock;
|
2017-02-13 20:20:35 +01:00
|
|
|
|
|
|
|
auto scheduler = dependencies.resolve!Scheduler;
|
|
|
|
scheduler.scheduleJob();
|
|
|
|
}
|