mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
42 lines
798 B
D
42 lines
798 B
D
/**
|
|
* Poodinis Dependency Injection Framework
|
|
* Copyright 2014-2023 Mike Bierlee
|
|
* 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;
|
|
|
|
class Driver
|
|
{
|
|
}
|
|
|
|
interface Database
|
|
{
|
|
}
|
|
|
|
class RelationalDatabase : Database
|
|
{
|
|
private Driver driver;
|
|
|
|
this(Driver driver)
|
|
{ // Automatically injected on creation by container
|
|
this.driver = driver;
|
|
}
|
|
}
|
|
|
|
class DataWriter
|
|
{
|
|
@Autowire private Database database; // Automatically injected when class is resolved
|
|
}
|
|
|
|
void main()
|
|
{
|
|
auto dependencies = new shared DependencyContainer();
|
|
dependencies.register!Driver;
|
|
dependencies.register!DataWriter;
|
|
dependencies.register!(Database, RelationalDatabase);
|
|
|
|
auto writer = dependencies.resolve!DataWriter;
|
|
}
|