So the way I understand this code I wrote, it is thread safe, as long as the retrievers and depositors are thread safe. The only bad state I could see occurring is that a thread is using a retriever as a method local while another thread calls RefreshDependencies(), which would mean the thread with it as a method local would continue to use it even though it wasn't one of the current depositors/retrievers, but that one should be cleaned up when the method local using it exited as there would be no root anymore.
also open to any other notes on the code.
public static class DependencyContainer
{
private const string DEPENDENCIES_LOCATION_APP_SETTINGS_KEY = "DependenciesLocation";
private static object _lockDependenciesManagement;
private static string _dependenciesLocation;
public static IEnumerable<IEntryRetriever> Retrievers { get; private set; }
public static IEnumerable<IEntryDepositor> Depositors { get; private set; }
static DependencyContainer()
{
_lockDependenciesManagement = new object();
string dependenciesLocation = ConfigurationManager.AppSettings[DEPENDENCIES_LOCATION_APP_SETTINGS_KEY] ?? typeof(DependencyContainer).Assembly.CodeBase.Replace(@"file:///", "");
SetDependenciesLocation(dependenciesLocation);
RefreshDependencies();
}
public static string GetDependenciesLocation()
{
lock (_lockDependenciesManagement)
{
return _dependenciesLocation;
}
}
public static void SetDependenciesLocation(string newDependenciesLocation)
{
lock (_lockDependenciesManagement)
{
_dependenciesLocation = newDependenciesLocation;
}
}
public static void RefreshDependencies()
{
lock (_lockDependenciesManagement)
{
// compose/load dependencies in here for writing and retrieving blog entries
}
}
}