mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 12:14:01 +01:00
9e5a27d046
The factory method encourages misuse of dependency injection (by using it as a service locator). Removing the factory method forces the user to make this choice deliberately.
25 lines
620 B
D
25 lines
620 B
D
/**
|
|
* Poodinis Dependency Injection Framework
|
|
* Copyright 2014-2016 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;
|
|
|
|
interface Database{};
|
|
class RelationalDatabase : Database {}
|
|
|
|
class DataWriter {
|
|
@Autowire
|
|
private Database database; // Automatically injected when class is resolved
|
|
}
|
|
|
|
void main() {
|
|
auto dependencies = new shared DependencyContainer();
|
|
dependencies.register!DataWriter;
|
|
dependencies.register!(Database, RelationalDatabase);
|
|
|
|
auto writer = dependencies.resolve!DataWriter;
|
|
}
|