public IRyuContainer Bootstrap(RyuConfiguration configuration) { if (configuration.IsDirectoryAssemblyLoadingEnabled()) { assemblyLoader.LoadAssembliesFromNeighboringDirectories(); } var modules = moduleLoader.LoadModules(configuration); var container = new RyuContainer(null, activator); moduleImporter.ImportModules(container, modules); return container; }
public IReadOnlyList<IRyuModule> LoadModules(RyuConfiguration configuration) { var modules = new List<IRyuModule>(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { var moduleTypes = assembly.GetTypes().Where(RyuModuleTypeFilter(configuration)); var moduleInstances = moduleTypes.Select(System.Activator.CreateInstance); modules.AddRange(moduleInstances.Cast<IRyuModule>()); } modules.AddRange(configuration.AdditionalModules); return modules; }
public IRyuFacade Create(RyuConfiguration configuration) { IAssemblyLoader assemblyLoader = new AssemblyLoader(logger); IModuleLoader moduleLoader = new ModuleLoader(); IActivator activator = new Activator(); IModuleSorter moduleSorter = new ModuleSorter(); IModuleImporter moduleImporter = new ModuleImporter(moduleSorter); var bootstrapper = new Bootstrapper(assemblyLoader, moduleLoader, activator, moduleImporter); var container = bootstrapper.Bootstrap(configuration); var facade = new RyuFacade(container, activator); facade.Initialize(); return facade; }
private Func<Type, bool> RyuModuleTypeFilter(RyuConfiguration configuration) { return (type) => { var moduleConfiguration = type.GetAttributeOrNull<ModuleConfigurationAttribute>(); if (configuration.ExcludedModuleTypes.Contains(type) || moduleConfiguration.IsManualLoadRequired()) { return false; } else { var moduleType = typeof(IRyuModule); return moduleType.IsAssignableFrom(type) && !type.IsAbstract; } }; }