mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Change getting of singleton dependency container to be thread-safe
This commit is contained in:
parent
f2eabe9797
commit
8d268846ed
|
@ -16,6 +16,7 @@ module poodinis.container;
|
||||||
import std.string;
|
import std.string;
|
||||||
import std.array;
|
import std.array;
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
|
import std.concurrency;
|
||||||
|
|
||||||
debug {
|
debug {
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
@ -44,9 +45,6 @@ class ResolveException : Exception {
|
||||||
* You can still create new instances of this class for exceptional situations.
|
* You can still create new instances of this class for exceptional situations.
|
||||||
*/
|
*/
|
||||||
class DependencyContainer {
|
class DependencyContainer {
|
||||||
|
|
||||||
private static DependencyContainer instance;
|
|
||||||
|
|
||||||
private Registration[][TypeInfo] registrations;
|
private Registration[][TypeInfo] registrations;
|
||||||
|
|
||||||
private Registration[] autowireStack;
|
private Registration[] autowireStack;
|
||||||
|
@ -273,10 +271,8 @@ class DependencyContainer {
|
||||||
/**
|
/**
|
||||||
* Returns a global singleton instance of a dependency container.
|
* Returns a global singleton instance of a dependency container.
|
||||||
*/
|
*/
|
||||||
public static DependencyContainer getInstance() {
|
public static shared(DependencyContainer) getInstance() {
|
||||||
if (instance is null) {
|
static shared DependencyContainer instance;
|
||||||
instance = new DependencyContainer();
|
return initOnce!instance(new DependencyContainer());
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue