-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swapped out StaticDataStoreRegistry for Scoped version. That will cau…
…se fewer issues with threadlocking and background jobs.
- Loading branch information
1 parent
f714ecb
commit 4390a44
Showing
20 changed files
with
104 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
|
||
namespace RCommon.Persistence | ||
{ | ||
public interface IScopedDataStore | ||
{ | ||
ConcurrentDictionary<string, Type> DataStores { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RCommon.Persistence | ||
{ | ||
public class ScopedDataStore : IScopedDataStore | ||
{ | ||
|
||
public ScopedDataStore() | ||
{ | ||
DataStores = new ConcurrentDictionary<string, Type>(); | ||
} | ||
|
||
public ConcurrentDictionary<string, Type> DataStores { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace RCommon.Persistence | ||
{ | ||
public class ScopedDataStoreRegistry : IDataStoreRegistry | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
private readonly IScopedDataStore _scopedDataStore; | ||
|
||
public ScopedDataStoreRegistry(IServiceProvider serviceProvider, IScopedDataStore scopedDataStore) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
_scopedDataStore = scopedDataStore; | ||
} | ||
|
||
public TDataStore GetDataStore<TDataStore>(string dataStoreName) where TDataStore : IDataStore | ||
{ | ||
var type = _scopedDataStore.DataStores.Where(x => x.Key == dataStoreName).FirstOrDefault().Value; | ||
Guard.Against<DataStoreNotFoundException>(type == null, | ||
this.GetGenericTypeName() + " could not find a DataStore with the key of: " + dataStoreName); | ||
return (TDataStore)this._serviceProvider.GetService(type); | ||
} | ||
|
||
public IDataStore GetDataStore(string dataStoreName) | ||
{ | ||
var type = _scopedDataStore.DataStores.Where(x => x.Key == dataStoreName).FirstOrDefault().Value; | ||
Guard.Against<DataStoreNotFoundException>(type == null, | ||
this.GetGenericTypeName() + " could not find a DataStore with the key of: " + dataStoreName); | ||
return (IDataStore)this._serviceProvider.GetService(type); | ||
} | ||
|
||
public void RegisterDataStore<TDataStore>(TDataStore dataStore, string dataStoreName) where TDataStore : IDataStore | ||
{ | ||
if (!_scopedDataStore.DataStores.TryAdd(dataStoreName, typeof(TDataStore))) | ||
{ | ||
throw new UnsupportedDataStoreException($"The ScopedDataStore refused to add the new DataStore name: {dataStoreName} of type: {dataStore.GetType().AssemblyQualifiedName}"); | ||
} | ||
} | ||
|
||
public void RemoveRegisteredDataStore(string dataStoreName) | ||
{ | ||
if (!_scopedDataStore.DataStores.TryRemove(dataStoreName, out _)) | ||
{ | ||
throw new UnsupportedDataStoreException($"The ScopedDataStore refused to remove the DataStore name: {dataStoreName}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters