poodinis/example/quickstart/app.d

36 lines
795 B
D
Raw Normal View History

2016-01-06 20:28:25 +01:00
/**
* Poodinis Dependency Injection Framework
2023-01-11 00:01:51 +01:00
* Copyright 2014-2023 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;
class Driver {
}
interface Database {
}
class RelationalDatabase : Database {
private Driver driver;
this(Driver driver) { // Automatically injected on creation by container
this.driver = driver;
}
}
2016-01-06 20:28:25 +01:00
class DataWriter {
@Inject private Database database; // Automatically injected when class is resolved
2016-01-06 20:28:25 +01:00
}
void main() {
auto dependencies = new shared DependencyContainer();
dependencies.register!Driver;
2016-01-06 20:28:25 +01:00
dependencies.register!DataWriter;
dependencies.register!(Database, RelationalDatabase);
auto writer = dependencies.resolve!DataWriter;
}