Is this code thread-safe - Singleton Implementation using Concurrent Dictionary
Never create two connection objects with the same parameters. If one exists, use it.


If you really need to guarantee this, then I think you will need to use locking instead of ConcurrentDictionary.

If it's okay to create duplicate Connections (that will never be used) in rare circumstances, then you can use an overload of GetOrAdd() that takes a lambda that creates the Connection:

return activeConnections.GetOrAdd(
    Tuple.Create(param1,param2), _ =&gt; new Connection (param1, param2));


With your current code, every time you call getInstance(), a new Connection is created and then most of the time thrown away.