Skip to content

This plugin manager allows you to import views and controllers from * .dll and * .views.dll files in a simple and transparent way

License

Notifications You must be signed in to change notification settings

GianfriAur/NETCore.Mvc.PluginsManager

Repository files navigation

NETCore.Mvc.PluginsManager

this library allows to have and manage plugins in the .netCore mvc projects. it is practical to manage the views both compiled in the * .views.dll file and as embedded resources. in addition it also allows you to manage additional controls that may be present in a plugin that adds functionality. in the future it is also necessary to manage the aggintic content that may be present in wwwroot.

use it is easy and comfortable look below for details

installation from nuget

PM>Install-Package AUR.NETCore.Mvc.PluginsManager -Version 1.0.0

or from nuget page

how to start

using AUR.NETCore.Mvc.PluginsManager;

Constructors

Base

PluginsManager PM = new PluginsManager<interfaces.IPluginBase>("absolutePath of plugin");
Example
const string PluginFolder = "Plugins";
static PluginsManager<interfaces.IPluginBase> _Plugins;
public static PluginsManager<interfaces.IPluginBase> Plugins { 
    get { 
        if (_Plugins == null) 
            _Plugins = new PluginsManager<interfaces.IPluginBase>(Path.Combine(AppContext.BaseDirectory, PluginFolder)); 
        return _Plugins; 
    }
}

Load

public void ConfigureServices(IServiceCollection services)
{
    //...
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    Plugins.Load(services); // last row
}

Configure

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
   //....
    Plugins.Configure(app, env);    // before default route

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

    });
}

types of configuration

public enum ViewsTypeResouces
{
    Assembly,
    Embedded,
    None
}
public enum ControllerTypeResouces
{
    Assembly,
    None
}

here is an example of a plugin

using Microsoft.AspNetCore.Hosting;
using AUR.NETCore.Mvc.PluginsManager.interfaces;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace CompiledView_WithoutControllers
{
    internal class CompiledView_WithoutControllers : IPluginBase
    {
        public string Name { get => "CompiledView_WithoutControllers"; }
        public ViewsTypeResouces ViewsTypeResouces { get => ViewsTypeResouces.Assembly; }
        public ControllerTypeResouces ControllerTypeResouces { get => ControllerTypeResouces.None; }

        public void PluginConfigure(IApplicationBuilder app, IHostingEnvironment env)
        {
            //
        }

        public void PluginConfigureServices(IServiceCollection services)
        {
            //
        }
    }
}

here is an example of a costum plugin

common interface between project and plugin
public interface CostumPlugin : IPluginBase
{
    void Do();
    string version { get; }
}
main project inizialize
const string PluginFolder = "Plugins";
static PluginsManager<CostumPlugin> _Plugins;
public static PluginsManager<CostumPlugin> Plugins { get { if (_Plugins == null) _Plugins = new PluginsManager<CostumPlugin>(Path.Combine(AppContext.BaseDirectory, PluginFolder)); return _Plugins; } }
here is an example of a plugin
using Microsoft.AspNetCore.Hosting;
using AUR.NETCore.Mvc.PluginsManager.interfaces;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace CompiledView_WithoutControllers
{
    internal class CompiledView_WithoutControllers : CostumPlugin
    {
        public string Name { get => "CompiledView_WithoutControllers"; }
        public string version { get => "v0.1.23"; }
        public ViewsTypeResouces ViewsTypeResouces { get => ViewsTypeResouces.Assembly; }
        public ControllerTypeResouces ControllerTypeResouces { get => ControllerTypeResouces.None; }

        public void PluginConfigure(IApplicationBuilder app, IHostingEnvironment env)
        {
            //
        }

        public void PluginConfigureServices(IServiceCollection services)
        {
            //
        }
        public void Do()
        {
            // my do
        }
    }
}

About

This plugin manager allows you to import views and controllers from * .dll and * .views.dll files in a simple and transparent way

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages