public static Provider GetInstance <T>() where T : Provider { Provider instance; try { instance = DoGetInstance(typeof(T)); } catch (Exception e) { Logger.GetInstance(typeof(Provider)).Fatal("Instance initialization error: " + e); Logger.GetInstance(typeof(Provider)).Info("Initializing " + typeof(NamedPipeIpcChannel.Provider).FullName + "..."); instance = new NamedPipeIpcChannel.Provider(); } return(instance); }
private static Provider DoGetInstance(Type type) { if (type == null) { throw new ArgumentException("Invalid arguments to get " + typeof(Provider).Name + " instance"); } var key = type.FullName + "_"; Provider instance = null; if (Instances.ContainsKey(key)) { instance = Instances[key]; } if (instance == null) { Logger.GetInstance(typeof(Provider)).Info("Initializing " + key + "..."); var constructor = type.GetConstructor(new Type[] { }); if (constructor != null) { instance = (Provider)constructor.Invoke(new object[] { }); } } if (instance == null) { Logger.GetInstance(typeof(Provider)).Info("Initializing " + typeof(NamedPipeIpcChannel.Provider).FullName + "..."); instance = new NamedPipeIpcChannel.Provider(); } lock (InstancesLock) { if (!Instances.ContainsKey(key)) { Instances.Add(key, instance); } } return(instance); }