private static void CreatePoolWithConnectionstrings <T>(int poolSize, Action <T> initializationCode) where T : ConnectionStringPoolableBase, new() { lock (Pools) { if (Pools.ContainsKey(typeof(T))) { PoolContainerBase oldContainer; if (!Pools.TryRemove(typeof(T), out oldContainer)) { throw new InvalidOperationException("Unable to remove old pool"); } oldContainer.DisposeAll(false); } var newPool = new ConnectionStringPoolContainer <T>(poolSize, initializationCode); Pools.AddOrIgnore(typeof(T), newPool); } }