Exemplo n.º 1
0
        /// <summary>
        ///     Initialize method that registers all plugins and triggers the starter
        /// </summary>
        private void RegisterPlugins()
        {
            _pluginAddressManager = new PluginAddressManager();

            var assemblies = _pluginFolder.GetFiles(FileNamePatternToRun, SearchOption.AllDirectories)
                             .Select(x =>
            {
                _pluginAddressManager?.Add(x.FullName);
                return(AssemblyName.GetAssemblyName(x.FullName));
            })
                             .Select(x => Assembly.Load(x.FullName));

            foreach (var assembly in assemblies)
            {
                //Add the plugin as a reference to the application
                Extensions.AddApplicationPart(_mvcBuilder, assembly);

                var type = assembly.GetTypes().FirstOrDefault(t => t.GetInterface(typeof(IPluginModule).Name) != null);

                if (type != null)
                {
                    //Add the modules to the PluginManager to manage them later
                    var module = (IPluginModule)Activator.CreateInstance(type);
                    PluginManager.Modules.Add(module, assembly);
                }
            }

            _pluginAddressManager = null;
        }