-
Notifications
You must be signed in to change notification settings - Fork 19
Plugin Manager Setup and Configuration
Adding ASPNet Core to a new or existing project is extremely easy, and involves only a few steps.
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>();`
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();
}`
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 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
}
}`
The Plugin Manager is configured using settings contained in appsettings.json.
Add an entry called PluginConfiguration, the following Properties can be set:
Bool, if true the Plugin Manager will be disabled and not load any plugins.
String, Path to plugin files, these will be loaded in any order.
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.
String, root path that is used to search for plugins loaded via the PluginFiles property.
String, path where css files will be placed after being extracted from Plugin modules.
String, Path where .js files will be placed after being extracted from Plugin modules
Bool, reserved for future use.
Array of plugin settings for individual Plugin modules.
String, Name of Plugin module.
Bool, if true, the Plugin module will not be loaded.
Bool, if true resources will not be extracted from the Plugin module.
Bool, if false existing resources will not be replaced.
String, Version of plugin to load, this can be "latest" (default value), or specific version i.e. 1.0.1.