Skip to content

This library allows to develop plugin-based AspNetCore project development.

License

Notifications You must be signed in to change notification settings

enisn/Modularity.AspNetCore

Repository files navigation

Modularity.AspNetCore

This library allows to import your class libraries with controllers to your main project. So you can easily use plug-in & plug-out your features.

Releases

Nuget

Nuget

Badges

CodeFactor Build status


Modularity AspNetCore_v2


Getting Started

Firstly you'll need a main project and at least one module project. Let's start with creating them

Creating Main Project

  • Create an AspNetCore project as main web project.

  • Add Modularity.AspNetCore package to your project.

  • Go your Startup and add following codes to MvcBuilder in ConfigureServices():

   public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
                .AddModularity(); // <-- Add this line after AddMvc method


            services.AddModuleServices(Configuration); // <-- Add this to add module's services into DI Container.
        }
  • Go Configure() method and add following code:
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseModulartiy(env); // <-- Call UseModularity with HostingEnvirorment parameter

            //...

        }
  • That's it! Your Main Application is ready to load all modules from Plugins folder.

  • (OPTIONAL) You can manage your modules with config file. Just create following plugins.json file under Plugins folder:

[
  {
    "Name": "MyFirstPlugin",
    "IsActive": true,
    "LoadAllDependencies" :  true
  },
  {
    "Name": "MySecondPlugin",
    "IsActive": false,
    "LoadAllDependencies" :  true
  }
]

If you use configuration file, you need to place your modules their own folders like this:

image

To automaticly copy after build your modules with folders, change build action like this:

xcopy "$(OutDir)*" "$(SolutionDir)MyMainWebApplication\Plugins\$(ProjectName)\" /Y

MyMainWebApplication: This is your main host application.


Creating a Module

    public class Startup : IModuleStartup
    {
        public IConfiguration Configuration { get; private set; }
        public void Initialize(IConfiguration configuration)
        {
            this.Configuration = configuration; // Get main application's configuration and keep it to use in ConfigureServices()
        }

        public void ConfigureServices(IServiceCollection services)
        {
            /* Do your services configurations */
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            /* Do your application configurations  */
        }
    }
  • (OPTIONAL) You can add following code to Build Events to copy your module DLLs to your main application's Plugins folder. If they're in same solution.
xcopy "$(OutDir)*" "$(SolutionDir)MyMainWebApplication\Plugins\" /Y

MyMainWebApplication: Your main web application name.

About

This library allows to develop plugin-based AspNetCore project development.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published