diag: Assert ViewStreamDatabase.instance is only created once
The instance must be initialized via ViewStreamDatabase.SetGlobalInstance
This commit is contained in:
1 parent
1d46ea061a
commit
970555d2a1
1 file changed
+13
-20
@@ -1,5 +1,7 @@
|
||||
using BCG.Utilities.General;
|
||||
|
||||
using bts;
|
||||
|
||||
using Bts.PubSub;
|
||||
|
||||
using System;
|
||||
@@ -30,30 +32,19 @@ namespace BCG {
|
||||
public ViewStreamDatabase(ISubscriberCoreFactory subscriberCoreFactory)
|
||||
: this(subscriberCoreFactory.Create()) { }
|
||||
|
||||
// This ctr is private to ensure the ISubscriberCore is created by ISubscriberCoreFactory
|
||||
// (we'll temporarily continue to use it internally to create ViewStreamDatabase.instance,
|
||||
// but new code should use the factory). The factory itself is created via dependency
|
||||
// injection so it has the correct runtime config (for pubsub routing, etc.).
|
||||
// This ctr is private to ensure the ISubscriberCore is created by ISubscriberCoreFactory. The
|
||||
// factory itself is created via dependency injection so it has the correct runtime config
|
||||
// (for pubsub routing, etc.).
|
||||
ViewStreamDatabase(ISubscriberCore subscriberCore) {
|
||||
mySubscriberCore = subscriberCore;
|
||||
}
|
||||
|
||||
public static ViewStreamDatabase instance {
|
||||
get {
|
||||
if (mySelf == null || mySelf.myIsDisposed)
|
||||
lock (myInstanceLockObject) {
|
||||
if (mySelf == null || mySelf.myIsDisposed) {
|
||||
mySelf = new ViewStreamDatabase(new SubscriberCore());
|
||||
}
|
||||
}
|
||||
return mySelf;
|
||||
}
|
||||
set {
|
||||
lock (myInstanceLockObject) {
|
||||
if (mySelf != null)
|
||||
mySelf.mySubscriberCore.Dispose();
|
||||
mySelf = value;
|
||||
}
|
||||
var rv = mySelf;
|
||||
Log.notnull(rv);
|
||||
Log.assert(!rv.myIsDisposed);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,8 +188,10 @@ namespace BCG {
|
||||
}
|
||||
|
||||
internal static void SetGlobalInstance(ViewStreamDatabase vsd) {
|
||||
Log.isnull(mySelf);
|
||||
mySelf = vsd;
|
||||
lock (myInstanceLockObject) {
|
||||
Log.isnull(mySelf);
|
||||
mySelf = vsd;
|
||||
}
|
||||
}
|
||||
|
||||
private List<PendingAddRemoveWorker> _pending_worker_ops = new List<PendingAddRemoveWorker>();
|
||||
|
||||
Reference in new issue
Block a user