poodinis/example/annotations/app.d
Mike Bierlee 63404b7d5a
Some checks failed
CI / dmd-2.086.1 on ubuntu-latest (push) Failing after 4s
CI / dmd-2.087.1 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.088.1 on ubuntu-latest (push) Failing after 4s
CI / dmd-2.089.1 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.090.1 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.091.1 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.092.1 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.093.1 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.094.2 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.095.1 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.096.1 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.097.2 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.098.1 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.099.1 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.100.2 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.101.2 on ubuntu-latest (push) Failing after 3s
CI / dmd-2.102.2 on ubuntu-latest (push) Failing after 3s
CI / dmd-latest on ubuntu-latest (push) Failing after 3s
CI / ldc-1.16.0 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.17.0 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.18.0 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.19.0 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.20.1 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.21.0 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.22.0 on ubuntu-latest (push) Failing after 2s
CI / ldc-1.23.0 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.24.0 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.26.0 on ubuntu-latest (push) Failing after 2s
CI / ldc-1.27.1 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.28.1 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.29.0 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.30.0 on ubuntu-latest (push) Failing after 3s
CI / ldc-1.31.0 on ubuntu-latest (push) Failing after 4s
CI / ldc-1.32.0 on ubuntu-latest (push) Failing after 3s
CI / ldc-latest on ubuntu-latest (push) Failing after 3s
CI / GDC on Ubuntu (push) Failing after 3s
CI / dmd-latest on windows-latest (push) Has been cancelled
CI / ldc-latest on windows-latest (push) Has been cancelled
Update copyrights
2025-02-01 22:35:17 +01:00

67 lines
1.8 KiB
D

/**
* Poodinis Dependency Injection Framework
* Copyright 2014-2025 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 SecurityAuditor {
void submitAudit() {
writeln("Hmmmyes I have received your audit. It is.... adequate.");
}
}
class SuperSecurityDevice {
private int seed;
this() {
auto randomGenerator = Random(unpredictableSeed);
seed = uniform(0, 999, randomGenerator);
}
string getPassword() {
return to!string(seed) ~ "t1m3sp13!!:";
}
}
class SecurityManager {
@Inject private SuperSecurityDevice levelOneSecurity;
@Inject @AssignNewInstance private SuperSecurityDevice levelTwoSecurity;
@Inject @OptionalDependency private SecurityAuditor auditor;
void doAudit() {
if (auditor !is null) {
auditor.submitAudit();
} else {
writeln("I uh, will skip the audit for now...");
}
}
}
void main() {
auto dependencies = new shared DependencyContainer();
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!!!!!"); // Should not be printed since levelTwoSecurity is a new instance.
} else {
writeln("Security okay!");
}
manager.doAudit(); // Will not cause the SecurityAuditor to print, since we didn't register a SecurityAuditor.
}