/// <summary>Find and registers Autofac modules that are implemented as plugins.</summary> public static void FindAndRegisterModules(ContainerBuilder builder) { var modules = MefPluginScanner.FindPlugins(builder, typeof(Module)); foreach (var module in modules) { InitializationLogging.Logger.Trace(() => "Registering module: " + module.Type.FullName); builder.RegisterModule((Module)Activator.CreateInstance(module.Type)); } }
/// <summary> /// Scans for plugins that implement the given export type (it is usually the plugin's interface), and registers them. /// The function should be called from a plugin module initialization (from Autofac.Module implementation). /// </summary> /// <param name="genericImplementationBase"> /// The genericImplementationBase is a generic interface or a generic abstract class that the plugin implements. /// The concept type that the plugin handles will be automatically extracted from the generic argument of the genericImplementationBase. /// This is an alternative to using MefProvider.Implements in the plugin's ExportMetadata attribute. /// </param> public static void FindAndRegisterPlugins <TPluginInterface>(ContainerBuilder builder, Type genericImplementationBase) { var matchingPlugins = MefPluginScanner.FindPlugins(builder, typeof(TPluginInterface)); foreach (var plugin in matchingPlugins) { ExtractGenericPluginImplementsMetadata(plugin, genericImplementationBase); } RegisterPlugins(builder, matchingPlugins, typeof(TPluginInterface)); }
//================================================================ #region Find and register plugins /// <summary> /// Scans for plugins that implement the given export type (it is usually the plugin's interface), and registers them. /// The function should be called from a plugin module initialization (from Autofac.Module implementation). /// </summary> public static void FindAndRegisterPlugins <TPluginInterface>(ContainerBuilder builder) { var matchingPlugins = MefPluginScanner.FindPlugins(builder, typeof(TPluginInterface)); RegisterPlugins(builder, matchingPlugins, typeof(TPluginInterface)); }
/// <summary>Deletes the plugins cache to allow scanning of the new generated dlls.</summary> public static void ClearCache() { MefPluginScanner.ClearCache(); }