I wrote this factory class in order to pass parameter to Singlton class, is it a good design in term of design for multithreading environment?public static class LoggingServiceFactory{    private static string _connectionstring;    private static readonly Lazy<LoggingService> _INSTANCE = new Lazy<LoggingService>(() => new LoggingService(_connectionstring));    public static ILoggingService GetService(string connectionString)    {        _connectionstring = connectionString;        return _INSTANCE.Value;    }    private class LoggingService : ILoggingService    {        private string _connectionstring;        internal LoggingService(string connectionString)        {            _connectionstring = connectionString;        }        public void LogMessage(string msg)        {            // do the logging work        }    }}public interface ILoggingService{    void LogMessage(string msg);}
Passing parameter to singleton
c#
If connection string matching is a really necessary thing:static class LoggingServiceFactory{    static readonly TaskCompletionSource<string> _cs = new TaskCompletionSource<string>();    static ILoggingService _service;    public static ILoggingService GetService(string connectionString)    {        if (_cs.TrySetResult(connectionString))            _service = new LoggingService(connectionString);        else            if (_cs.Task.Result != connectionString)                throw new InvalidOperationException(Connection string redefinition.);        return _service;    }}