2016-01-06 20:28:25 +01:00
|
|
|
/**
|
|
|
|
* Poodinis Dependency Injection Framework
|
2022-02-17 22:45:03 +01:00
|
|
|
* Copyright 2014-2022 Mike Bierlee
|
2016-01-06 20:28:25 +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;
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
class Driver
|
|
|
|
{
|
|
|
|
}
|
2016-09-03 18:19:38 +02:00
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
interface Database
|
|
|
|
{
|
|
|
|
}
|
2016-09-03 18:19:38 +02:00
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
class RelationalDatabase : Database
|
|
|
|
{
|
2016-09-03 18:19:38 +02:00
|
|
|
private Driver driver;
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
this(Driver driver)
|
|
|
|
{ // Automatically injected on creation by container
|
2016-09-03 18:19:38 +02:00
|
|
|
this.driver = driver;
|
|
|
|
}
|
|
|
|
}
|
2016-01-06 20:28:25 +01:00
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
class DataWriter
|
|
|
|
{
|
|
|
|
@Autowire private Database database; // Automatically injected when class is resolved
|
2016-01-06 20:28:25 +01:00
|
|
|
}
|
|
|
|
|
2021-05-01 21:16:44 +02:00
|
|
|
void main()
|
|
|
|
{
|
2016-08-08 22:17:17 +02:00
|
|
|
auto dependencies = new shared DependencyContainer();
|
2016-09-03 18:19:38 +02:00
|
|
|
dependencies.register!Driver;
|
2016-01-06 20:28:25 +01:00
|
|
|
dependencies.register!DataWriter;
|
|
|
|
dependencies.register!(Database, RelationalDatabase);
|
|
|
|
|
|
|
|
auto writer = dependencies.resolve!DataWriter;
|
|
|
|
}
|