mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add example project demonstrating @AssignNewInstance
This commit is contained in:
parent
3e11ff1e92
commit
a59e7a9731
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,6 +4,7 @@
|
|||
/quickstartExample.exe
|
||||
/qualifiersExample.exe
|
||||
/arrayCompletionExample.exe
|
||||
/annotationsExample.exe
|
||||
/.settings
|
||||
/.dub
|
||||
/dub.selections.json
|
||||
|
@ -16,3 +17,4 @@
|
|||
/quickstartExample
|
||||
/qualifiersExample
|
||||
/arrayCompletionExample
|
||||
/annotationsExample
|
||||
|
|
12
dub.json
12
dub.json
|
@ -66,6 +66,18 @@
|
|||
"importPaths": [
|
||||
"source"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name" : "annotationsExample",
|
||||
"description" : "Example where several Poodinis autowire annotations are demonstrated.",
|
||||
"targetType": "executable",
|
||||
"targetName": "annotationsExample",
|
||||
"sourcePaths": [
|
||||
"example/annotations"
|
||||
],
|
||||
"importPaths": [
|
||||
"source"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
43
example/annotations/app.d
Normal file
43
example/annotations/app.d
Normal file
|
@ -0,0 +1,43 @@
|
|||
import poodinis;
|
||||
|
||||
import std.random;
|
||||
import std.digest.md;
|
||||
import std.stdio;
|
||||
import std.conv;
|
||||
|
||||
class SuperSecurityDevice {
|
||||
private int seed;
|
||||
|
||||
public this() {
|
||||
auto randomGenerator = Random(unpredictableSeed);
|
||||
seed = uniform(0, 999, randomGenerator);
|
||||
}
|
||||
|
||||
public string getPassword() {
|
||||
return to!string(seed) ~ "t1m3sp13!!:";
|
||||
}
|
||||
}
|
||||
|
||||
class SecurityManager {
|
||||
@Autowire
|
||||
public SuperSecurityDevice levelOneSecurity;
|
||||
|
||||
@Autowire
|
||||
@AssignNewInstance
|
||||
public SuperSecurityDevice levelTwoSecurity;
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto dependencies = DependencyContainer.getInstance();
|
||||
dependencies.register!SuperSecurityDevice; // Registered with the default "Single instance" scope
|
||||
dependencies.register!SecurityManager;
|
||||
|
||||
auto manager = dependencies.resolve!SecurityManager;
|
||||
|
||||
writeln("Password for user one: " ~ manager.levelOneSecurity.getPassword());
|
||||
writeln("Password for user two: " ~ manager.levelTwoSecurity.getPassword());
|
||||
|
||||
if (manager.levelOneSecurity is manager.levelTwoSecurity) {
|
||||
writeln("SECURITY BREACH!!!!!");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue