internal static void LoadAssembliesInDirrectory() { var path = Path.Combine(Directory.GetCurrentDirectory(), "Modules"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var files = Directory.EnumerateFiles(path).Where(x => x.Contains("HeroBot.Plugins")); foreach (var file in files) { if (!file.Contains(".dll")) { continue; } var moduleContext = new ModuleLoadContext(); var ass = moduleContext.LoadFromAssemblyPath(file); RuntimeAssemblies.AssemblyEntities.TryAdd(ass.GetName().Name, new AssemblyEntity() { Assembly = ass, Context = moduleContext }); } }
/// <summary> /// Start micake application. /// Must provider <see cref="IServiceProvider"/> /// </summary> public virtual void Start() { if (AppServiceProvider == null) { throw new ArgumentNullException(nameof(AppServiceProvider)); } if (_isStarted) { throw new InvalidOperationException($"MiCake has already started."); } //Pre activation ServiceLocator AppServiceProvider.GetService(typeof(IServiceLocator)); //Module Inspection. var inspectContext = new ModuleInspectionContext(AppServiceProvider, ModuleContext.AllModules); foreach (var module in ModuleContext.AllModules) { if (module is IModuleSelfInspection selfInspection) { selfInspection.Inspect(inspectContext); } } var context = new ModuleLoadContext(AppServiceProvider, ModuleContext.AllModules, ApplicationOptions); _miCakeModuleBoot.Initialization(context); //Release options additional infomation. ApplicationOptions.AdditionalInfo.Release(); }
/// <summary> /// Shudown micake application /// </summary> public virtual void ShutDown() { if (_isShutdown) { throw new InvalidOperationException($"MiCake has already shutdown."); } var context = new ModuleLoadContext(AppServiceProvider, ModuleContext.AllModules, ApplicationOptions); _miCakeModuleBoot.ShutDown(context); _appServiceScope?.Dispose(); }
private void LoadFromPath(DirectoryPath path) { var registrationBuilder = BootstrapperConventions.GetRegistrationBuilder(); var moduleFiles = Directory.GetFiles(path.ToString(), moduleNamePattern); var moduleCatalogs = moduleFiles.Select(x => { var loadContext = new ModuleLoadContext(x); var assembly = loadContext.LoadFromAssemblyPath(x); return(new AssemblyCatalog(assembly, registrationBuilder) as ComposablePartCatalog); }).ToArray(); var applicationCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly(), registrationBuilder); var aggregateCatalog = new AggregateCatalog(moduleCatalogs.Append(applicationCatalog)); container = new CompositionContainer(aggregateCatalog); }
private void FetchExternalAssemblies() { var path = Directory.GetCurrentDirectory(); // Path.Combine(Directory.GetCurrentDirectory(), "Modules"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var files = Directory.EnumerateFiles(path).Where(x => x.Contains("Assembly")); foreach (var file in files) { if (!file.Contains(".dll")) { continue; } var moduleContext = new ModuleLoadContext(); var ass = moduleContext.LoadFromAssemblyPath(file); var name = ass.GetName().Name.SanitizAssembly(); var context = new ContextEntity { Name = name, Context = moduleContext, Assembly = ass }; if (_contexts.ContainsKey(name)) { continue; } _contexts.TryAdd(name, context); ConsoleHelper.Log(LogSeverity.Info, "Core", $"Loaded {name} v{ass.GetName().Version} assembly."); } if (!_contexts.IsEmpty) { return; } ConsoleHelper.Log(LogSeverity.Warning, "Core", "No external assemblies were found."); }
public override void Initialization(ModuleLoadContext context) { var provider = context.ServiceProvider; //activate all mapping relationship between persistent object and domain object. var persistentObjectActivator = provider.GetService <IPersistentObjectActivator>(); using (var currentScope = provider.CreateScope()) { var mapper = currentScope.ServiceProvider.GetService <IPersistentObjectMapper>(); if (mapper.InitAtStartup) { //need to initialize automatically persistentObjectActivator.SetMapper(mapper); persistentObjectActivator.ActivateMapping(); } } }
private IEnumerable <Module> LoadModules() { var modules = new List <Module>(); var path = Path.Combine(Environment.CurrentDirectory, "Modules", "Modbus.dll"); var moduleLoadContext = new ModuleLoadContext(path); var assembly = moduleLoadContext.LoadFromAssemblyName(new System.Reflection.AssemblyName(Path.GetFileNameWithoutExtension(path))); foreach (Type type in assembly.GetTypes()) { if (typeof(Module).IsAssignableFrom(type)) { try { modules.Add(Activator.CreateInstance(type) as Module); } catch (Exception) { } } } return(modules); }
public override void Initialization(ModuleLoadContext context) { }
public virtual void Shutdown(ModuleLoadContext context) { }
public virtual void PreShutDown(ModuleLoadContext context) { }
public virtual void PreInitialization(ModuleLoadContext context) { }
public override void Initialization(ModuleLoadContext context) { // [Cancel:See Azure Board #ISSUE 12] // DiagnosticListener.AllListeners.Subscribe(new EfGlobalListener(context.ServiceProvider)); }