I have a singleton (because i thought it would be usefull to have these available all the time) to represent some settings, which will clear the old and load the new settings from the database at the beginning of the clr procedure call.
But if CLR calls are handled like threads I will probably get the problem at some point that the settings are cleared in exact that moment I want to access them.
So will this be an issues? Can I work around this with a simple object lock?
EDIT:
Code Sample Settings:
public class Settings
{
public static Settings Default
{
get { return _default ?? (_default = new Settings()); }
}
private static Settings _default;
private Dictionary<string, string> _settingsDict;
private Settings()
{
_settingsDict = new Dictionary<string, string>();
}
public void ReloadSettings()
{
_settingsDict.Clear();
using (var connection = new SqlConnection("context connetion=true"))
using (var command = connection.CreateCommand())
{
command.CommandText = ...
connection.Open();
// Read Settings with DataReader into _settingsDict
}
}
public string Get(string key) {
get { return _settingsDict["key"] }
}
}
Procedure:
[SqlProcedure]
public static void InsertData(SqlString csv)
{
Settings.Default.ReloadSettings();
var setting = Settings.Default.Get("SETTING");
using (var connection = new SqlConnection("context connetion=true"))
using (var command = connection.CreateCommand())
{
...
}
}