Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/enisn/modularity.aspnetcore
This library allows to develop plugin-based AspNetCore project development.
https://github.com/enisn/modularity.aspnetcore
Last synced: 4 months ago
JSON representation
This library allows to develop plugin-based AspNetCore project development.
- Host: GitHub
- URL: https://github.com/enisn/modularity.aspnetcore
- Owner: enisn
- License: mit
- Created: 2019-07-29T17:07:28.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T02:03:26.000Z (about 2 years ago)
- Last Synced: 2024-05-01T14:50:32.777Z (10 months ago)
- Language: C#
- Size: 730 KB
- Stars: 14
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
[](https://www.nuget.org/packages/Modularity.AspNetCore/)[](https://www.nuget.org/packages/Modularity.Core/)
## Badges
[](https://www.codefactor.io/repository/github/enisn/modularity.aspnetcore)
[](https://ci.appveyor.com/project/enisn/modularity-aspnetcore)***

***
# 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](https://www.nuget.org/packages/Modularity.AspNetCore/) package to your project.
- Go your **Startup** and add following codes to MvcBuilder in **ConfigureServices()**:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddModularity(); // <-- Add this line after AddMvc methodservices.AddModuleServices(Configuration); // <-- Add this to add module's services into DI Container.
}
```- Go **Configure()** method and add following code:
```csharp
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:
```json
[
{
"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:

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
- Create a .Net Core class library.
- Add [Modularity.AspNetCore.Abstractions](https://www.nuget.org/packages/Modularity.AspNetCore.Abstractions) package to project.
- Add [Modularity.Core.Abstractions](https://www.nuget.org/packages/Modularity.Core.Abstractions) package to project.
- Create a class and inherit from `IModuleStartup`. This class will be used initialization.
```csharp
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.