English | 中文
🔌 适用于
ASP.NET Core
的轻量级插件框架 | Vue.js frontend | JavaScript SDK
🔌 适用于 ASP.NET Core
的轻量级插件框架 | Vue.js frontend | JavaScript SDK
wwwroot
文件夹下放置前端文件 (index.html,...), 然后访问 /plugins/pluginId/index.html
HTTP request pipeline middleware
, 也无需重启站点IPlugin
的插件类的构造方法上申请依赖注入项, 当然 Controller
构造方法上也可依赖注入SharpZipLib
)i18n
的国际化实现, 提供多语言切换支持关联线上产品: https://120365.xyz
推荐使用 NuGet, 在你项目的根目录 执行下方的命令, 如果你使用 Visual Studio, 这时依次点击 Tools -> NuGet Package Manager -> Package Manager Console , 确保 "Default project" 是你想要安装的项目, 输入下方的命令进行安装.
PM> Install-Package PluginCore.AspNetCore
在你的 ASP.NET Core 应用程序中修改代码
Startup.cs
using PluginCore.AspNetCore.Extensions;
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
// 1. 添加 PluginCore
services.AddPluginCore();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
// 2. 使用 PluginCore
app.UsePluginCore();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
现在访问 https://localhost:5001/PluginCore/Admin 即可进入 PluginCore Admin
https://localhost:5001 需改为你的地址
请登录 PluginCore Admin
后,为了安全,及时修改默认用户名,密码:
App_Data/PluginCore.Config.json
{
"Admin": {
"UserName": "admin",
"Password": "ABC12345"
},
"FrontendMode": "LocalEmbedded",
"RemoteFrontend": "https://cdn.jsdelivr.net/gh/yiyungent/plugincore-admin-frontend@0.1.2/dist-cdn"
}
修改后,立即生效,无需重启站点,需重新登录 PluginCore Admin
如果你需要在本地体验 PluginCore, 那么这里有一个 例子(/examples)
docker run -d -p 5004:80 -e ASPNETCORE_URLS="http://*:80" --name plugincore-aspnetcore3-1 yiyungent/plugincore-aspnetcore3-1
现在你可以访问 http://localhost:5004/PluginCore/Admin
补充:
若使用Docker Compose
, 可参考仓库根目录下的docker-compose.yml
补充:
使用ghcr.io
docker run -d -p 5004:80 -e ASPNETCORE_URLS="http://*:80" --name plugincore-aspnetcore3-1 ghcr.io/yiyungent/plugincore-aspnetcore3-1
1.例如,自定义插件钩子:
ITestPlugin
using PluginCore.IPlugins;
namespace PluginCore.IPlugins
{
public interface ITestPlugin : IPlugin
{
string Say();
}
}
2.在需要激活的地方,应用钩子,这样所有启用的插件中,实现了
ITestPlugin
的插件,都将调用Say()
using PluginCore;
using PluginCore.IPlugins;
namespace WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
private readonly PluginFinder _pluginFinder;
public TestController(PluginFinder pluginFinder)
{
_pluginFinder = pluginFinder;
}
public ActionResult Get()
{
//var plugins = PluginFinder.EnablePlugins<BasePlugin>().ToList();
// 所有实现了 ITestPlugin 的已启用插件
var plugins2 = _pluginFinder.EnablePlugins<ITestPlugin>().ToList();
foreach (var item in plugins2)
{
// 调用
string words = item.Say();
Console.WriteLine(words);
}
return Ok("");
}
}
}
PluginCore 支持3种前端文件加载方式
配置文件
App_Data/PluginCore.Config.json
中FrontendMode
PluginCore
源代码,重新编译,不建议PluginCore
的 ASP.NET Core 项目中, 新建 PluginCoreAdmin
, 将前端文件放入此文件夹RemoteFrontend
指定url注意:
更新FrontendMode
, 需重启站点后, 才能生效
补充
开发插件只需要, 添加对
PluginCore.IPlugins
包 (插件sdk) 的引用即可,当然如果你需要
PluginCore
, 也可以添加引用
规范
- 插件sdk
插件接口应当位于
PluginCore.IPlugins
命名空间,这是规范,不强求,但建议这么做,程序集名不一定要与命名空间名相同,你完全在你的插件sdk程序集中,使用
PluginCore.IPlugins
命名空间。
- 插件
插件程序集名(一般=项目(Project)名) 与 插件
info.json
中PluginId
一致, 例如: Project:HelloWorldPlugin
, PluginId:HelloWorldPlugin
, 此项必须,否则插件无法加载PluginId
为插件唯一标识
自
PluginCore.IPlugins-v0.8.0
起,PluginCore
项目重构,PluginCore
只包含核心插件逻辑,ASP.NET Core
需要使用PluginCore.AspNetCore
PluginCore.IPlugins | 0.8.0 | 0.8.0 | 0.8.0 | 0.8.0 | 0.8.0 | 0.8.0 | 0.8.0 | 0.8.0 | 0.8.0 | 0.8.0 | 0.8.0 | 0.8.0 | 0.9.0 | 0.9.0 | 0.9.0 | 0.9.0 | 0.9.1 | 0.9.1 | 0.9.1 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PluginCore | 1.0.0 | 1.0.0 | 1.0.0 | 1.0.0 | 2.0.0 | 2.0.0 | 2.0.1 | 2.0.1 | 2.0.1 | 2.0.2 | 2.0.2 | 2.1.0 | 2.2.0 | 2.2.1 | 2.2.2 | 2.2.2 | 2.2.3 | 2.2.3 | 2.2.4 |
PluginCore.IPlugins.AspNetCore | 0.0.1 | 0.0.1 | 0.0.1 | 0.0.1 | 0.0.1 | 0.0.1 | 0.0.1 | 0.0.1 | 0.0.1 | 0.0.1 | 0.0.1 | 0.0.1 | 0.1.0 | 0.1.0 | 0.1.0 | 0.1.0 | 0.1.1 | 0.1.1 | 0.1.1 |
PluginCore.AspNetCore | 0.0.2 | 0.0.3 | 0.0.4 | 0.0.5 | 0.0.5 | 1.0.0 | 1.0.1 | 1.0.2 | 1.0.3 | 1.0.4 | 1.1.0 | 1.2.0 | 1.3.1 | 1.3.2 | 1.3.2 | 1.3.3 | 1.3.4 | 1.4.0 | 1.4.1 |
plugincore-admin-frontend | 0.1.0 - 0.3.1 | 0.1.0 - 0.3.1 | 0.1.0 - 0.3.1 | 0.1.0 - 0.3.1 | 0.1.0 - 0.3.1 | 0.1.0 - 0.3.1 | 0.1.0 - 0.3.1 | 0.3.2 | 0.3.2 | 0.3.2 | 0.3.2 | 0.3.2 | 0.3.2 | 0.3.2 | 0.3.2 | 0.3.2 | 0.3.2 | 0.3.2 | 0.3.2 |
plugincore-js-sdk | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 | 0.1.0 - 0.5.0 |
下方为旧版依赖, 仅作存档
PluginCore.IPlugins | 0.1.0 | 0.1.0 | 0.2.0 | 0.2.0 | 0.2.0 | 0.3.0 | 0.3.0 | 0.4.0 | 0.5.0 | 0.6.0 | 0.6.0 | 0.6.0 | 0.6.0 | 0.6.1 | 0.6.1 | 0.6.1 | 0.7.0 | 0.7.0 | 0.7.0 | 0.7.0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PluginCore | 0.1.0 | 0.2.0 | 0.3.0 | 0.3.1 | 0.4.0 | 0.5.0 | 0.5.1 | 0.6.0 | 0.7.0 | 0.8.0 | 0.8.1 | 0.8.2 | 0.8.3 | 0.8.4 | 0.8.5 | 0.8.6 | 0.9.0 | 0.9.1 | 0.9.2 | 0.9.3 |
plugincore-admin-frontend | 0.1.0 | 0.1.2 | 0.1.2 | 0.1.3 | 0.1.3 | 0.2.0 | 0.2.0 | 0.2.0 | 0.2.0 | 0.2.0 | 0.2.3 | 0.2.3 | 0.2.3 | 0.2.3 | 0.3.0 | 0.3.0 | 0.3.0 | 0.3.0 | 0.3.0 | 0.3.1 |
plugincore-js-sdk | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | 0.1.0 | 0.1.0 | 0.1.0 | 0.1.0 |
PluginCore.IPlugins | ||
---|---|---|
PluginCore | ||
PluginCore.IPlugins.AspNetCore | ||
PluginCore.AspNetCore | ||
PluginCore.Template | ||
plugincore-admin-frontend | ||
plugincore-js-sdk |
TODO:
PluginCore is an GNU LGPLv3 licensed open source project and completely free to use. However, the amount of effort needed to maintain and develop new features for the project is not sustainable without proper financial backing.
We accept donations through these channels:
PluginCore © yiyun, Released under the GNU LGPLv3 License.
Authored and maintained by yiyun with help from contributors (list).
GitHub @yiyungent Gitee @yiyungent
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。