Open Source Web Application Framework for ASP.NET Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2.3 KiB

Plug-In Modules

It is possible to load modules as plug-ins. That means you may not reference to a module's assembly in your solution, but you can load that module in the application startup just like any other module.

Basic Usage

IServiceCollection.AddApplication<T>() extension method can get options to configure the plug-in sources.

Example: Load plugins from a folder

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity.PlugIns;

namespace MyPlugInDemo.Web
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplication<MyPlugInDemoWebModule>(options =>
            {
                options.PlugInSources.AddFolder(@"D:\Temp\MyPlugIns");
            });
        }

        public void Configure(IApplicationBuilder app)
        {
            app.InitializeApplication();
        }
    }
}
  • This is the Startup class of a typical ASP.NET Core application.
  • PlugInSources.AddFolder gets a folder path and to load assemblies (typically dlls) in that folder.

That's all. ABP will discover the modules in the given folder, configure and initialize them just like regular modules.

Plug-In Sources

options.PlugInSources is actually a list of IPlugInSource implementations and AddFolder is just a shortcut for the following expression:

options.PlugInSources.Add(new FolderPlugInSource(@"D:\Temp\MyPlugIns"));

AddFolder() only looks for the assembly file in the given folder, but not looks for the sub-folders. You can pass SearchOption.AllDirectories as a second parameter to explore plug-ins also from the sub-folders, recursively.

There are two more built-in Plug-In Source implementations:

  • PlugInSources.AddFiles() gets a list of assembly (typically dll) files. This is a shortcut of using FilePlugInSource class.
  • PlugInSources.AddTypes() gets a list of module class types. If you use this, you need to load the assemblies of the modules yourself, but it provides flexibility when needed. This is a shortcut of using TypePlugInSource class.

If you need, you can create your own IPlugInSource implementation and add to the options.PlugInSources just like the others.