mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Move initializer to its own example
This commit is contained in:
parent
bb4eaf8676
commit
89512e0cb0
12
dub.json
12
dub.json
|
@ -135,6 +135,18 @@
|
|||
"importPaths": [
|
||||
"source"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "injectionInitializerExample",
|
||||
"description" : "Example where the usage of an injection initializer is demonstrated.",
|
||||
"targetType": "executable",
|
||||
"targetName": "injectionInitializerExample",
|
||||
"sourcePaths": [
|
||||
"example/injectioninitializer"
|
||||
],
|
||||
"importPaths": [
|
||||
"source"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
* The full terms of the license can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import std.stdio;
|
||||
|
||||
class Scheduler {
|
||||
private Calendar calendar;
|
||||
|
||||
|
@ -36,17 +38,9 @@ class Calendar {
|
|||
}
|
||||
}
|
||||
|
||||
import std.stdio;
|
||||
|
||||
class HardwareClock {
|
||||
// Parameterless constructors will halt any further selection of constructors.
|
||||
this() {
|
||||
writeln("default constructor");
|
||||
}
|
||||
|
||||
this(string name) {
|
||||
writeln(name);
|
||||
}
|
||||
this() {}
|
||||
|
||||
// As a result, this constructor will not be used when HardwareClock is created.
|
||||
this(Calendar calendar) {
|
||||
|
@ -64,10 +58,7 @@ void main() {
|
|||
auto dependencies = new shared DependencyContainer();
|
||||
dependencies.register!Scheduler;
|
||||
dependencies.register!Calendar;
|
||||
dependencies.register!HardwareClock( {
|
||||
writeln("Running the creator");
|
||||
return new HardwareClock("clock name");
|
||||
});
|
||||
dependencies.register!HardwareClock;
|
||||
|
||||
auto scheduler = dependencies.resolve!Scheduler;
|
||||
scheduler.scheduleJob();
|
||||
|
|
24
example/injectioninitializer/app.d
Normal file
24
example/injectioninitializer/app.d
Normal file
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* Poodinis Dependency Injection Framework
|
||||
* Copyright 2014-2021 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;
|
||||
import std.stdio;
|
||||
|
||||
class Doohickey
|
||||
{
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
auto dependencies = new shared DependencyContainer();
|
||||
dependencies.register!Doohickey({
|
||||
writeln("Creating Doohickey via initializer delegate.");
|
||||
return new Doohickey();
|
||||
});
|
||||
|
||||
dependencies.resolve!Doohickey;
|
||||
}
|
|
@ -202,7 +202,7 @@ synchronized class DependencyContainer {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Deduplicate code
|
||||
*/
|
||||
Registration register(SuperType, ConcreteType : SuperType)(InjectionInitializer!SuperType initializer,
|
||||
RegistrationOption options = RegistrationOption.none)
|
||||
|
|
Loading…
Reference in a new issue