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