Exemple #1
0
        public ModuleCollection()
        {
            var allAssembly = AssemblyHelper.Load();

            foreach (var assembly in allAssembly)
            {
                var resources = assembly.GetManifestResourceNames();
                var name      = resources.FirstOrDefault(m => m.EndsWith("_module.json"));
                if (name.IsNull())
                {
                    continue;
                }

                var stream = assembly.GetManifestResourceStream(name);
                if (stream == null)
                {
                    continue;
                }

                //读取流并解析配置信息
                var sr = new StreamReader(stream);
                var moduleDescriptor = JsonConvert.DeserializeObject <ModuleDescriptor>(sr.ReadToEnd());

                sr.Close();
                stream.Close();

                if (moduleDescriptor != null)
                {
                    //判断是否已存在
                    if (!_list.Any(m => m.Name.Equals(moduleDescriptor.Name)))
                    {
                        //此处默认模块命名空间前缀与当前项目相同
                        var assemblyDescriptor = new ModuleAssemblyDescriptor
                        {
                            Domain         = AssemblyHelper.LoadByNameEndString($"Module.{moduleDescriptor.Id}.Domain"),
                            Infrastructure = AssemblyHelper.LoadByNameEndString($"Module.{moduleDescriptor.Id}.Infrastructure"),
                            Application    = AssemblyHelper.LoadByNameEndString($"Module.{moduleDescriptor.Id}.Application"),
                            Quartz         = AssemblyHelper.LoadByNameEndString($"Module.{moduleDescriptor.Id}.Quartz")
                        };

                        Check.NotNull(assemblyDescriptor.Domain, moduleDescriptor.Id + "模块的Domain程序集未发现");
                        Check.NotNull(assemblyDescriptor.Infrastructure, moduleDescriptor.Id + "模块的Infrastructure程序集未发现");
                        Check.NotNull(assemblyDescriptor.Application, moduleDescriptor.Id + "模块的Application程序集未发现");

                        moduleDescriptor.AssemblyDescriptor = assemblyDescriptor;

                        Add(moduleDescriptor);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 加载程序集信息
        /// </summary>
        private void LoadAssemblyDescriptor(ModuleDescriptor moduleDescriptor)
        {
            //此处默认模块命名空间前缀与当前项目相同
            var assemblyDescriptor = new ModuleAssemblyDescriptor
            {
                Domain         = AssemblyHelper.LoadByNameEndString($"Module.{moduleDescriptor.Id}.Domain"),
                Infrastructure = AssemblyHelper.LoadByNameEndString($"Module.{moduleDescriptor.Id}.Infrastructure"),
                Application    = AssemblyHelper.LoadByNameEndString($"Module.{moduleDescriptor.Id}.Application"),
                Quartz         = AssemblyHelper.LoadByNameEndString($"Module.{moduleDescriptor.Id}.Quartz")
            };

            CheckAssemblyDescriptor(moduleDescriptor, assemblyDescriptor);

            moduleDescriptor.AssemblyDescriptor = assemblyDescriptor;
        }