2016-01-06 20:28:25 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
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
|
2016-02-09 21:06:07 +01:00
|
|
|
private SuperSecurityDevice levelOneSecurity;
|
2016-01-06 20:28:25 +01:00
|
|
|
|
|
|
|
@Autowire
|
|
|
|
@AssignNewInstance
|
2016-02-09 21:06:07 +01:00
|
|
|
private SuperSecurityDevice levelTwoSecurity;
|
2016-01-06 20:28:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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!!!!!");
|
|
|
|
}
|
|
|
|
}
|