public static IServiceCollection AddModules(this IServiceCollection services, string rootPath) { const string moduleManifestName = "module.json"; var modulesFolder = Path.Combine(rootPath, "Modules"); foreach (var module in _modulesConfig.GetModules()) { var moduleFolder = new DirectoryInfo(Path.Combine(modulesFolder, module.FriendlyName, "netcoreapp2.2")); var moduleSettings = Path.Combine(moduleFolder.FullName, moduleManifestName); using (var reader = new StreamReader(moduleSettings)) { string content = reader.ReadToEnd(); dynamic moduleMetaData = JsonConvert.DeserializeObject(content); module.DisplayName = moduleMetaData.DisplayName; } module.Assembly = Assembly.LoadFrom(Path.Combine(moduleFolder.FullName, module.FriendlyName + ".dll")); GlobalConfiguration.Modules.Add(module); RegisterModuleManager(module, ref services); } return(services); }
public static IServiceCollection AddModules(this IServiceCollection services, string contentRootPath) { var modulesFolder = Path.Combine(contentRootPath, "Modules"); IEnumerable <ModuleInfo> moduleInfos = null; if (!Directory.Exists(modulesFolder)) { //add current assembly and core. var currentAssembly = System.Reflection.Assembly.GetEntryAssembly(); var coreAssembly = System.Reflection.Assembly.Load("RCommerce.Module.Core"); moduleInfos = new[] { new ModuleInfo { Assembly = coreAssembly, Name = coreAssembly.FullName, Version = Version.Parse("1.0") }, new ModuleInfo { Assembly = currentAssembly, Name = currentAssembly.FullName, Version = Version.Parse("1.0") }, }; } else { moduleInfos = _modulesConfig.GetModules(modulesFolder); } foreach (var module in moduleInfos) { GlobalConfiguration.Modules.Add(module); RegisterModuleInitializerServices(module, ref services); } return(services); }
public static IServiceCollection AddModules(this IServiceCollection services, string contentRootPath) { const string moduleManifestName = "module.json"; var modulesFolder = Path.Combine(contentRootPath, "Modules"); foreach (var module in _modulesConfig.GetModules()) { var moduleFolder = new DirectoryInfo(Path.Combine(modulesFolder, module.Id)); var moduleManifestPath = Path.Combine(moduleFolder.FullName, moduleManifestName); if (!File.Exists(moduleManifestPath)) { throw new MissingModuleManifestException($"The manifest for the module '{moduleFolder.Name}' is not found.", moduleFolder.Name); } using (var reader = new StreamReader(moduleManifestPath)) { string content = reader.ReadToEnd(); dynamic moduleMetadata = JsonConvert.DeserializeObject(content); module.Name = moduleMetadata.name; } TryLoadModuleAssembly(moduleFolder.FullName, out Assembly moduleAssembly); if (moduleAssembly == null) { moduleAssembly = Assembly.Load(new AssemblyName(moduleFolder.Name)); } module.Assembly = moduleAssembly; GlobalConfiguration.Modules.Add(module); RegisterModuleInitializerServices(module, ref services); } return(services); }
public static IServiceCollection AddModules(this IServiceCollection services, string contentRootPath) { var modulesFolder = Path.Combine(contentRootPath, "Modules"); foreach (var module in _moduleConfig.GetModules()) { var moduleFolder = new DirectoryInfo(Path.Combine(modulesFolder, module.Id)); module.Name = module.Id; module.Assembly = Assembly.Load(new AssemblyName(moduleFolder.Name)); GlobalConfiguration.Modules.Add(module); RegisterModuleServices(module, ref services); } return(services); }
public static IServiceCollection AddModules(this IServiceCollection services, string contentRootPath) { const string moduleManifestName = "module.json"; var modulesFolder = Path.Combine(contentRootPath, "Modules"); foreach (var module in modulesConfig.GetModules()) { var moduleFolder = new DirectoryInfo(Path.Combine(modulesFolder, module.Id)); var moduleManifestPath = Path.Combine(moduleFolder.FullName, moduleManifestName); if (!File.Exists(moduleManifestPath)) { // done! todo: create MissingModuleManifestException throw new MissingModuleManifestException($"The manifest for the module '{moduleFolder.Name}' is not found."); } using (var reader = new StreamReader(moduleManifestPath)) { var content = reader.ReadToEnd(); dynamic moduleMetadata = JsonConvert.DeserializeObject(content); module.Name = moduleMetadata.name; module.IsBundledWithHost = moduleMetadata.isBundledWithHost; } // if is not bundled if (!module.IsBundledWithHost) { // done! todo: add method to this class: TryLoadModuleAssembly TryLoadModuleAssembly(moduleFolder.FullName, module); if (module.Assembly == null) { throw new Exception($"Cannot find main assembly for {module.Id}"); } } else { module.Assembly = Assembly.Load(new AssemblyName(moduleFolder.Name)); } GlobalConfiguration.Modules.Add(module); // done! todo: registermoduleinitializerservices RegisterModuleInitializerServices(module, ref services); } return(services); }
public static IServiceCollection AddModules(this IServiceCollection services) { foreach (var module in _modulesConfig.GetModules()) { if (!module.IsBundledWithHost) { TryLoadModuleAssembly(module.Id, module); if (module.Assembly == null) { throw new Exception($"Cannot find main assembly for module {module.Id}"); } } else { module.Assembly = Assembly.Load(new AssemblyName(module.Id)); } GlobalConfiguration.Modules.Add(module); } return(services); }
public static IServiceCollection AddModules(this IServiceCollection services, string contentRootPath) { // No need module.json at the moment. Consider put as embbeded resource if needed //const string moduleManifestName = "module.json"; //var modulesFolder = Path.Combine(contentRootPath, "Modules"); foreach (var module in _modulesConfig.GetModules()) { //var moduleFolder = new DirectoryInfo(Path.Combine(modulesFolder, module.Id)); //var moduleManifestPath = Path.Combine(moduleFolder.FullName, moduleManifestName); //if (!File.Exists(moduleManifestPath)) //{ // throw new MissingModuleManifestException($"The manifest for the module '{moduleFolder.Name}' is not found.", moduleFolder.Name); //} //using (var reader = new StreamReader(moduleManifestPath)) //{ // string content = reader.ReadToEnd(); // dynamic moduleMetadata = JsonConvert.DeserializeObject(content); // module.Name = moduleMetadata.name; //} if (!module.IsBundledWithHost) { TryLoadModuleAssembly(module.Id, module); if (module.Assembly == null) { throw new Exception($"Cannot find main assembly for module {module.Id}"); } } else { module.Assembly = Assembly.Load(new AssemblyName(module.Id)); } GlobalConfiguration.Modules.Add(module); } return(services); }
public static IServiceCollection AddModules(this IServiceCollection services, string contentRootPath) { const string moduleManifestName = "module.json"; var modulesFolder = Path.Combine(contentRootPath, "Modules"); foreach (var item in _moduleCfManager.GetModules()) { var moduleFolder = new DirectoryInfo(Path.Combine(modulesFolder, item.Id)); var moduleManifestPath = Path.Combine(moduleFolder.FullName, moduleManifestName); if (!File.Exists(moduleManifestPath)) { throw new Exception($"The manifest for the module '{moduleFolder.Name}' is not found."); } using(var reader = new StreamReader(moduleManifestPath)) { string content = reader.ReadToEnd(); dynamic moduleMetaData = JsonConvert.DeserializeObject(content); item.Name = moduleMetaData.name; item.IsBundledWithHost = moduleMetaData.isBundledWithHost; } item.Assembly = Assembly.Load(new AssemblyName(moduleFolder.Name)); GlobalConfiguration.Modules.Add(item); } return services; }
public static IServiceCollection AddModules(this IServiceCollection services, string contentRootPath) { const string moduleManifestName = "module.json"; var modulesFolder = Path.Combine(contentRootPath, "Modules"); var dirPath = Assembly.GetExecutingAssembly().Location; dirPath = Path.GetDirectoryName(dirPath); foreach (var module in _modulesConfig.GetModules()) { try { var moduleFolder = new DirectoryInfo(Path.Combine(modulesFolder, module.Id)); var moduleManifestPath = Path.Combine(moduleFolder.FullName, moduleManifestName); if (!File.Exists(moduleManifestPath)) { throw new MissingModuleManifestException($"The manifest for the module '{moduleFolder.Name}' is not found.", moduleFolder.Name); } using (var reader = new StreamReader(moduleManifestPath)) { string content = reader.ReadToEnd(); dynamic moduleMetadata = JsonConvert.DeserializeObject(content); module.Name = moduleMetadata.name; module.IsBundledWithHost = moduleMetadata.isBundledWithHost; } if (!module.IsBundledWithHost) { TryLoadModuleAssembly(moduleFolder.FullName, module); if (module.Assembly == null) { throw new Exception($"Cannot find main assembly for module {module.Id}"); } } else { try { module.Assembly = Assembly.Load(new AssemblyName(moduleFolder.Name)); } catch (Exception ex) { AssemblyName a = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(assembly => assembly.GetName().Name == moduleFolder.Name).GetName(); module.Assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(a); } // This will get the current PROJECT directory //string projectDirectory = Directory.GetParent(workingDirectory).Parent.FullName; } if (module.Assembly.FullName.Contains(moduleFolder.Name)) { module.Name = moduleFolder.Name; module.Path = Path.Combine(modulesFolder, module.Id); } GlobalConfiguration.Modules.Add(module); RegisterModuleInitializerServices(module, ref services); } catch (Exception ex) { ex.Message.ToString(); } } return(services); }