/// <summary> /// 注册程序集中的所有类型,通过反射来进行注册 /// </summary> /// <param name="objectConfiguration"></param> private static void RegisterTypeOrInstanceToUnity(Config.ConfigurationItem objectConfiguration) { try { //判断配置的值 if (string.IsNullOrEmpty(objectConfiguration.Value)) { return; } var assemblyNames = objectConfiguration.Value.Split(';'); if (assemblyNames.Length == 0) { return; } foreach (var assemblyName in assemblyNames) { if (string.IsNullOrEmpty(assemblyName)) { continue; } RegisterAssemblyEventHandler(assemblyName, objectConfiguration.LifeCycle); } } catch (Exception) { #if DEBUG throw; #endif } }
/// <summary> /// 注册程序集中的所有类型,通过反射来进行注册 /// </summary> /// <param name="objectConfiguration"></param> private static void RegisterTypeOrInstanceToUnity(Config.ConfigurationItem objectConfiguration) { try { //判断配置的值 if (string.IsNullOrEmpty(objectConfiguration.Value)) { return; } //获取程序集名称,判断是否已经有后缀 string assemblyName = objectConfiguration.Value; if (assemblyName.LastIndexOf(".dll") < 0) { assemblyName += ".dll"; } string assemblyPath = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, assemblyName); //判断程序集是否存在 if (!System.IO.File.Exists(assemblyPath)) { return; } //装载程序集 System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(assemblyPath); //如果装载失败 if (assembly == null) { return; } //反射得到所有的程序集中的类型 Type[] types = assembly.GetTypes(); //循环所有的类型,准备注册 foreach (var type in types) { if (type.IsAbstract || type.IsInterface || type.IsGenericType) { continue; } //if (Config.PlatformConfig.ServerConfig.IOCSetting.InterceptionItems.Where(pre => System.IO.Path.GetFileNameWithoutExtension(pre.AssemblyName) == (System.IO.Path.GetFileNameWithoutExtension(objectConfiguration.Value))).Count() == 0) //判断如果注册拦截其器则拦截,否则不拦截 // RegisterType(type, objectConfiguration.LifeCycle); //else RegisterType(type, objectConfiguration.LifeCycle); } } catch (Exception) { #if DEBUG throw; #endif } }
/// <summary> /// 注册程序集中的所有类型,通过反射来进行注册 /// </summary> /// <param name="objectConfiguration"></param> private void RegisterTypeOrInstanceToUnity(Config.ConfigurationItem objectConfiguration) { try { var tempArray = new string[] { "all", "online" }; if (!string.IsNullOrEmpty(objectConfiguration.LineMode) && !(tempArray.Contains(objectConfiguration.LineMode.ToLower()))) { return; } //判断配置的值 if (string.IsNullOrEmpty(objectConfiguration.Value) || objectConfiguration.Value.Split(';').Length == 0) { return; } string[] items = objectConfiguration.Value.Split(';'); foreach (var assemblyFilter in items) { if (string.IsNullOrEmpty(assemblyFilter)) { continue; } RegisterTypeFromAssembly(assemblyFilter, objectConfiguration.LifeCycle); } } catch (Exception ex) { log4netLogger.Debug("注册类型的过程中出现错误", ex); #if DEBUG throw; #endif } }
/// <summary> /// 注册程序集中的所有类型,通过反射来进行注册 /// </summary> /// <param name="objectConfiguration"></param> private static void RegisterTypeOrInstanceToUnity(Config.ConfigurationItem objectConfiguration) { try { //判断配置的值 if (string.IsNullOrEmpty(objectConfiguration.Value)) { return; } if (objectConfiguration.Value.Split(';').Length == 0) { return; } var tempAssemblys = objectConfiguration.Value.Split(';'); foreach (var tempAssembly in tempAssemblys) { if (string.IsNullOrEmpty(tempAssembly)) { continue; } //获取程序集名称,判断是否已经有后缀 string assemblyName = tempAssembly; var searchName = tempAssembly.Replace(".dll", "").Replace(".Dll", "").Replace(".DLL", ""); if (assemblyName.ToLower().LastIndexOf(".dll") < 0) { assemblyName += ".dll"; } string assemblyPath = string.Empty; var tempKeyValuePair = PlatformConfig.ServerConfig.KeyValueSettings.KeyValueItems.Where(pre => pre.Key.ToLower() == "ioc").FirstOrDefault(); if (tempKeyValuePair != null && tempKeyValuePair.Value.ToLower() == "gac") { assemblyPath = GACAssemblys.Where(pre => pre.Split(',')[0].Contains(searchName)).FirstOrDefault(); } //装载程序集 System.Reflection.Assembly assembly = null; if (string.IsNullOrEmpty(assemblyPath)) { assemblyPath = System.IO.Path.Combine(PlatformConfig.ServerConfig.IOCSetting.AssemblyFilePath, assemblyName); //判断程序集是否存在 if (!System.IO.File.Exists(assemblyPath)) { return; } //装载程序集 assembly = System.Reflection.Assembly.LoadFrom(assemblyPath); } else { //装载程序集 assembly = System.Reflection.Assembly.Load(assemblyPath); } //如果装载失败 if (assembly == null) { return; } //反射得到所有的程序集中的类型 Type[] types = assembly.GetTypes(); //循环所有的类型,准备注册 foreach (var type in types) { if (type.IsAbstract || type.IsInterface || type.IsGenericType) { continue; } RegisterType(type, objectConfiguration.LifeCycle); } } } catch (Exception) { #if DEBUG throw; #endif } }