public ValueTask Load(IPlugin plugin) { var pluginDesciptorAttr = plugin.GetType().GetCustomAttribute <EmberPluginAttribute>(); var pluginDesciptor = pluginDesciptorAttr.ToString(); try { if (plugin is IEntryComponent entry) { EntryComponents.Add(entry); } var pluginScope = PluginLayerScope.BeginLifetimeScope(plugin.GetType(), (builder) => plugin.BuildComponents(new ComponentBuilder(builder, PluginLayerScope))); if (!PluginScopes.ContainsKey(plugin)) { PluginScopes.Add(plugin, pluginScope); PluginStatus.Add(plugin, false); foreach (var entryRegistrion in pluginScope.ComponentRegistry.Registrations) { if (entryRegistrion.Activator.LimitType.IsAssignableTo <IEntryComponent>()) { EntryComponents.Add((IEntryComponent)pluginScope.Resolve(entryRegistrion.Activator.LimitType)); } } } else { PluginScopes[plugin] = pluginScope; } } catch (Exception e) { Logger.LogWarning(e, $"Can't load {pluginDesciptor}"); } PluginLoaded?.Invoke(PluginDescriptor.FromAttribute(pluginDesciptorAttr)); return(default);
public async ValueTask Initialize(IPlugin plugin) { if (PluginStatus.ContainsKey(plugin) && !PluginStatus[plugin]) { await plugin.Initialize(PluginScopes[plugin]); PluginStatus[plugin] = true; var pluginDesciptorAttr = plugin.GetType().GetCustomAttribute <EmberPluginAttribute>(); PluginInitialized?.Invoke(PluginDescriptor.FromAttribute(pluginDesciptorAttr)); } }