Skip to content

Plugin Manager Setup and Configuration

Si Carter edited this page Nov 2, 2018 · 2 revisions

Adding ASPNet Core to a new or existing project is extremely easy, and involves only a few steps.

Step 1 - Initialisation

To initialise the plugin Manager, within the Main entry point function, add the following line:

AspNetCore.PluginManager.PluginManagerService.Initialise(new Classes.Logger());

So the Main function would look like the following:

    `public static void Main(string[] args)
    {
        // Initialise the plugin manager service
        AspNetCore.PluginManager.PluginManagerService.Initialise(new Classes.Logger());

        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();`

Step 2 - Configure Services

This method allows the Plugin Manager to configure services for all Plugin modules. It must be called before the call to AddMvc()

using AspNetCore.PluginManager;

Add ConfigurePluginManager() to AddMvc() method

    `public void ConfigureServices(IServiceCollection services)
    {
        // Allow plugin manager to configure all services in each plugin
        PluginManagerService.ConfigureServices(services);

        services.AddMvc().ConfigurePluginManager();
    }`

Step 3 - Configure Application

The final step is configuring the application, again, the Plugin Manager must be called before the call to UseMvc().

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    `public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        // Allow plugin manager to configure options for all plugins
        PluginManagerService.Configure(app, env);

        app.UseStaticFiles();

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseCookiePolicy();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }`

ILogger

ILogger is a simple class which is used by the Plugin Manager to report error's, the same interface is also passed to each plugin module. This allows the host application to receive notifications of any load or runtime errors.

An example ILogger implementation would look like the following:

`public class Logger : AspNetCore.PluginManager.ILogger
{
    public void AddToLog(string data)
    {
      // log data
    }

    public void AddToLog(Exception exception)
    {
      // log exception
    }

    public void AddToLog(Exception exception, string data)
    {
      // log exception
    }
}`

Settings

The Plugin Manager is configured using settings contained in appsettings.json.

Add an entry called PluginConfiguration, the following Properties can be set:

Disabled

Bool, if true the Plugin Manager will be disabled and not load any plugins.

PluginPath

String, Path to plugin files, these will be loaded in any order.

PluginFiles

String[], collection of plugin modules to load, they will be loaded in the order which they appear. These plugins are loaded before generic plugins loaded via PluginPath.

PluginSearchPath

String, root path that is used to search for plugins loaded via the PluginFiles property.

CSSLocation

String, path where css files will be placed after being extracted from Plugin modules.

JScriptLocation

String, Path where .js files will be placed after being extracted from Plugin modules

PreventAreas

Bool, reserved for future use.

Plugins

Array of plugin settings for individual Plugin modules.

Name

String, Name of Plugin module.

Disabled

Bool, if true, the Plugin module will not be loaded.

PreventExtractResources

Bool, if true resources will not be extracted from the Plugin module.

ReplaceExistingResources

Bool, if false existing resources will not be replaced.

Version

String, Version of plugin to load, this can be "latest" (default value), or specific version i.e. 1.0.1.