Beispiel #1
0
 /// <summary>
 /// Searches for a compatible entry-point in every compatible plugin file found in the specified directory, and call its <see cref="IEntrypoint.Setup">Setup</see> method.
 /// </summary>
 /// <param name="directory">The plugin assemblies directory, that are loaded via reflection after being sorted alphabetically.</param>
 /// <param name="options">Options for the plugins loader.</param>
 /// <param name="pattern">Pattern to search for in the name of the files within the directory.</param>
 public static void LoadPlugins(this IExpandR expandr, DirectoryInfo directory, PluginLoaderOptions options = default, string pattern = DefaultDirPattern)
 {
     Directory.CreateDirectory(directory.FullName);
     foreach (var file in directory.GetFiles(pattern).OrderBy(dllPath => dllPath.Name))
     {
         expandr.LoadPlugin(file, options);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Searches for a compatible entry-point in every compatible plugin file found in the specified directory, and call its <see cref="IEntrypoint.Setup">Setup</see> method.
 /// </summary>
 /// <param name="path">Either the path of a directory or an existing file.</param>
 /// <param name="options">Options for the plugins loader.</param>
 /// <param name="pattern">Pattern to search for in the name of the files within the directory, if a directory path was supplied.</param>
 public static void LoadPlugins(this IExpandR expandr, string path, PluginLoaderOptions options = default, string pattern = DefaultDirPattern)
 {
     if (File.Exists(path))
     {
         expandr.LoadPlugin(new FileInfo(Path.GetDirectoryName(path)), options);
     }
     else
     {
         expandr.LoadPlugins(new DirectoryInfo(path), options, pattern);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Searches for a compatible entry-point in the specified file, and call its <see cref="IEntrypoint.Setup">Setup</see> method.
        /// </summary>
        /// <param name="file">The plugin assembly binary, to be loaded via reflection.</param>
        /// <param name="options">Options for the plugins loader.</param>
        public static void LoadPlugin(this IExpandR expandr, FileInfo file, PluginLoaderOptions options = default)
        {
            Assembly asm;

            try
            {
                asm = Assembly.LoadFrom(file.FullName);
            }
            catch (Exception ex)
            {
                options?.RaiseError(expandr, new PluginErrorEventArgs()
                {
                    Error = new PluginFileException(file, $"Invalid assembly file: {ex.Message}", ex)
                });
                return;
            }
            expandr.LoadPlugin(asm, options);
        }
Beispiel #4
0
 /// <summary>
 /// Exposes a service type to ExpandR, so that plugins may provide multiple implementations.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="lifetime">The lifetime of the service.</param>
 /// <param name="defaultFactory">Default factory implementation for the service.</param>
 public static void ExposeMulti <TService>(this IExpandR expandr, ServiceLifetime lifetime, Func <IServiceProvider, TService> defaultFactory)
 => expandr.Expose <TService>(lifetime, true, defaultFactory);
Beispiel #5
0
 /// <summary>
 /// Exposes a singleton service type to ExpandR, so that plugins may provide multiple implementations.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <typeparam name="TDefaultImpl">The default implementation type.</typeparam>
 public static void ExposeMultiSingleton <TService, TDefaultImpl>(this IExpandR expandr)
 => expandr.Expose <TService, TDefaultImpl>(ServiceLifetime.Singleton, true);
Beispiel #6
0
 /// <summary>
 /// Exposes a singleton service type to ExpandR, so that plugins may provide multiple implementations.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="defaultInstance">Default instance implementations for the service.</param>
 public static void ExposeMultiSingleton <TService>(this IExpandR expandr, TService defaultInstance)
 => expandr.Expose <TService>(ServiceLifetime.Singleton, true, _ => defaultInstance);
Beispiel #7
0
 /// <summary>
 /// Exposes a singleton service type to ExpandR, so that plugins may provide multiple implementations.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="defaultImpls">Default implementations for the service.</param>
 public static void ExposeMultiSingleton <TService>(this IExpandR expandr, Func <IServiceProvider, TService> defaultFactory)
 => expandr.Expose <TService>(ServiceLifetime.Singleton, true, defaultFactory);
Beispiel #8
0
 /// <summary>
 /// Exposes a singleton service type to ExpandR, so that plugins may provide multiple implementations.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="defaultImpls">Default implementations for the service.</param>
 public static void ExposeMultiSingleton <TService>(this IExpandR expandr, params ExposedImplementation[] defaultImpls)
 => expandr.Expose(typeof(TService), ServiceLifetime.Singleton, true, defaultImpls);
Beispiel #9
0
 /// <summary>
 /// Exposes a scoped service type to ExpandR, so that plugins may provide multiple implementations.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <typeparam name="TDefaultImpl">The default implementation type.</typeparam>
 public static void ExposeMultiScoped <TService, TDefaultImpl>(this IExpandR expandr)
 => expandr.Expose <TService, TDefaultImpl>(ServiceLifetime.Scoped, true);
Beispiel #10
0
 /// <summary>
 /// Exposes a transient service type to ExpandR, so that plugins can implement it.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <typeparam name="TDefaultImpl">The default implementation type.</typeparam>
 /// <param name="multiple">Whether the service can have multiple implementations, or at most one.</param>
 public static void ExposeTransient <TService, TDefaultImpl>(this IExpandR expandr, bool multiple = false)
 => expandr.Expose <TService, TDefaultImpl>(ServiceLifetime.Transient, multiple);
Beispiel #11
0
 /// <summary>
 /// Exposes a service type to ExpandR, so that plugins can implement it.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="lifetime">The lifetime of the service.</param>
 /// <param name="multiple">Whether the service can have multiple implementations, or at most one.</param>
 /// <param name="defaultImpls">Default implementation(s) for the service.</param>
 public static void Expose <TService>(this IExpandR expandr, ServiceLifetime lifetime, bool multiple = false, params ExposedImplementation[] defaultImpls)
 => expandr.Expose(typeof(TService), lifetime, multiple, defaultImpls);
Beispiel #12
0
 /// <summary>
 /// Searches for a compatible entry-point in every compatible plugin file found in the specified directory, and call its <see cref="IEntrypoint.Setup">Setup</see> method.
 /// </summary>
 /// <param name="directory">The plugin assemblies directory, that are loaded via reflection after being sorted alphabetically.</param>
 /// <param name="pattern">Pattern to search for in the name of the files within the directory.</param>
 public static void LoadPlugins(this IExpandR expandr, DirectoryInfo directory, string pattern)
 => expandr.LoadPlugins(directory, default, pattern);
Beispiel #13
0
 /// <summary>
 /// Exposes a singleton service type to ExpandR, so that plugins can implement it.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="defaultInstance">Default instance implementation for the service.</param>
 public static void ExposeSingleton <TService>(this IExpandR expandr, TService defaultInstance)
 => expandr.ExposeSingleton <TService>(false, _ => defaultInstance);
Beispiel #14
0
 /// <summary>
 /// Exposes a singleton service type to ExpandR, so that plugins can implement it.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="multiple">Whether the service can have multiple implementations, or at most one.</param>
 /// <param name="defaultInstance">Default instance implementation for the service.</param>
 public static void ExposeSingleton <TService>(this IExpandR expandr, bool multiple, TService defaultInstance)
 => expandr.Expose <TService>(ServiceLifetime.Singleton, multiple, _ => defaultInstance);
Beispiel #15
0
 /// <summary>
 /// Exposes a singleton service type to ExpandR, so that plugins can implement it.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <typeparam name="TDefaultImpl">The default implementation type.</typeparam>
 /// <param name="multiple">Whether the service can have multiple implementations, or at most one.</param>
 public static void ExposeSingleton <TService, TDefaultImpl>(this IExpandR expandr, bool multiple = false)
 => expandr.Expose <TService, TDefaultImpl>(ServiceLifetime.Singleton, multiple);
Beispiel #16
0
 /// <summary>
 /// Exposes a singleton service type to ExpandR, so that plugins can implement it.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="defaultFactory">Default factory implementation for the service.</param>
 /// <param name="multiple">Whether the service can have multiple implementations, or at most one.</param>
 public static void ExposeSingleton <TService>(this IExpandR expandr, Func <IServiceProvider, TService> defaultFactory, bool multiple = false)
 => expandr.ExposeSingleton <TService>(multiple, defaultFactory);
Beispiel #17
0
 /// <summary>
 /// Exposes a singleton service type to ExpandR, so that plugins can implement it.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="multiple">Whether the service can have multiple implementations, or at most one.</param>
 /// <param name="defaultImpls">Default implementation(s) for the service.</param>
 public static void ExposeSingleton <TService>(this IExpandR expandr, bool multiple = false, params ExposedImplementation[] defaultImpls)
 => expandr.Expose <TService>(ServiceLifetime.Singleton, multiple, defaultImpls);
Beispiel #18
0
 /// <summary>
 /// Exposes a scoped service type to ExpandR, so that plugins can implement it.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="multiple">Whether the service can have multiple implementations, or at most one.</param>
 /// <param name="defaultFactory">Default factory implementation for the service.</param>
 public static void ExposeScoped <TService>(this IExpandR expandr, bool multiple, Func <IServiceProvider, TService> defaultFactory)
 => expandr.Expose <TService>(ServiceLifetime.Scoped, multiple, defaultFactory);
Beispiel #19
0
 /// <summary>
 /// Exposes a transient service type to ExpandR, so that plugins may provide multiple implementations.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="defaultFactory">Default factory implementation for the service.</param>
 public static void ExposeMultiTransient <TService>(this IExpandR expandr, Func <IServiceProvider, TService> defaultFactory)
 => expandr.Expose <TService>(ServiceLifetime.Transient, true, defaultFactory);
Beispiel #20
0
 /// <summary>
 /// Exposes a transient service type to ExpandR, so that plugins may provide multiple implementations.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <typeparam name="TDefaultImpl">The default implementation type.</typeparam>
 public static void ExposeMultiTransient <TService, TDefaultImpl>(this IExpandR expandr)
 => expandr.Expose <TService, TDefaultImpl>(ServiceLifetime.Transient, true);
Beispiel #21
0
 /// <summary>
 /// Exposes a service type to ExpandR, so that plugins can implement it.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <param name="lifetime">The lifetime of the service.</param>
 /// <param name="multiple">Whether the service can have multiple implementations, or at most one.</param>
 /// <param name="defaultFactory">Default factory implementation for the service.</param>
 public static void Expose <TService>(this IExpandR expandr, ServiceLifetime lifetime, bool multiple, Func <IServiceProvider, TService> defaultFactory)
 => expandr.Expose(typeof(TService), lifetime, multiple, ExposedImplementation.FromFactory(defaultFactory));
Beispiel #22
0
 /// <summary>
 /// Exposes a service type to ExpandR, so that plugins can implement it.
 /// </summary>
 /// <typeparam name="TService">The service (interface) type.</typeparam>
 /// <typeparam name="TDefaultImpl">The default implementation type.</typeparam>
 /// <param name="lifetime">The lifetime of the service.</param>
 /// <param name="multiple">Whether the service can have multiple implementations, or at most one.</param>
 public static void Expose <TService, TDefaultImpl>(this IExpandR expandr, ServiceLifetime lifetime, bool multiple = false)
 => expandr.Expose(typeof(TService), lifetime, multiple, ExposedImplementation.FromType <TDefaultImpl>());