import{_ as h,c as p,e as l,a as i,b as a,d as e,w as t,r as k,o as d}from"./app-DlzW8FTI.js";const r={},g={class:"hint-container note"};function B(c,s){const n=k("RouteLink");return d(),p("div",null,[s[11]||(s[11]=l(`

插件入口类

ClassIsland 的插件需要定义一个插件入口类,插件入口类需要继承PluginBase抽象类,并添加PluginEntrance属性。下面是一个插件入口的示例:

Plugin.cs
using ClassIsland.Core.Abstractions;
using ClassIsland.Core.Attributes;
using ClassIsland.Core.Controls.CommonDialog;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace HelloWorldPlugin;

[PluginEntrance]
public class Plugin : PluginBase
{
    public override void Initialize(HostBuilderContext context, IServiceCollection services)
    {
    }
}

在上面的代码中,我们定义了一个名为Plugin的类,并继承了 PluginBase抽象类。同时为Plugin类添加了PluginEntrance属性,以声明这个类是插件入口类。

这个插件入口类也会在初始化时添加到 IoC 主机上,您可以在插件注册的服务中通过依赖注入获取插件入口类实例。

初始化方法

其中的Initialize初始化方法会在插件加载后马上执行。您可以在这个方法中完成插件初始化操作。下面的代码会在初始化时显示一个“Hello world!”弹窗。

Plugin.cs
// ...
namespace HelloWorldPlugin;

[PluginEntrance]
public class Plugin : PluginBase
{
    public override void Initialize(HostBuilderContext context, IServiceCollection services)
    {
        CommonDialog.ShowInfo("Hello world!");
    }

    // ...
}
`,8)),i("p",null,[s[1]||(s[1]=a("初始化方法传入了主机构造时所需的相关参数,注册")),e(n,{to:"/en-us/dev/components.html"},{default:t(()=>s[0]||(s[0]=[a("组件")])),_:1}),s[2]||(s[2]=a("、提醒提供方、服务等操作需要在这个方法完成。下面的代码会在初始化时注册一个名为 ")),s[3]||(s[3]=i("code",null,"ExampleSettingsPage",-1)),s[4]||(s[4]=a(" 的设置页面,和一个名为 ")),s[5]||(s[5]=i("code",null,"ExampleCompent",-1)),s[6]||(s[6]=a(" 的组件。"))]),s[12]||(s[12]=l(`
Plugin.cs
// ...
namespace PluginWithSettingsPage;

[PluginEntrance]
public class Plugin : PluginBase
{
    public Settings Settings { get; set; } = new();

    public override void Initialize(HostBuilderContext context, IServiceCollection services)
    {
        services.AddSettingsPage<ExampleSettingsPage>();
        services.AddComponent<ExampleComponent>();
    }

}
`,1)),i("div",g,[s[10]||(s[10]=i("p",{class:"hint-container-title"},"Note",-1)),i("p",null,[s[8]||(s[8]=a("有些注册操作需要在主机启动后进行,由于初始化方法在主机启动前执行,所以可以通过订阅")),e(n,{to:"/en-us/dev/events.html#%E5%BA%94%E7%94%A8%E5%90%AF%E5%8A%A8%E5%AE%8C%E6%88%90-appstarted"},{default:t(()=>s[7]||(s[7]=[i("code",null,"AppBase.AppStarted",-1)])),_:1}),s[9]||(s[9]=a("事件,在应用启动完成后进行注册。"))])]),s[13]||(s[13]=i("h2",{id:"获取插件信息",tabindex:"-1"},[i("a",{class:"header-anchor",href:"#获取插件信息"},[i("span",null,"获取插件信息")])],-1)),s[14]||(s[14]=i("p",null,[a("您可以通过访问"),i("code",null,"Info"),a("来获取这个插件的相关信息,比如插件清单等。您也可以通过访问"),i("code",null,"PluginConfigFolder"),a("来获取插件配置目录路径。")],-1))])}const o=h(r,[["render",B]]),y=JSON.parse('{"path":"/en-us/dev/plugins/plugin-base.html","title":"插件入口类","lang":"en-US","frontmatter":{"description":"插件入口类 ClassIsland 的插件需要定义一个插件入口类,插件入口类需要继承PluginBase抽象类,并添加PluginEntrance属性。下面是一个插件入口的示例: Plugin.cs 在上面的代码中,我们定义了一个名为Plugin的类,并继承了 PluginBase抽象类。同时为Plugin类添加了PluginEntrance属性,以声...","head":[["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"插件入口类\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-30T03:47:10.000Z\\",\\"author\\":[{\\"@type\\":\\"Person\\",\\"name\\":\\"ClassIsland 社区\\",\\"url\\":\\"https://classisland.tech\\"}]}"],["meta",{"property":"og:url","content":"https://docs.classisland.tech/en-us/dev/plugins/plugin-base.html"}],["meta",{"property":"og:site_name","content":"ClassIsland Documentation"}],["meta",{"property":"og:title","content":"插件入口类"}],["meta",{"property":"og:description","content":"插件入口类 ClassIsland 的插件需要定义一个插件入口类,插件入口类需要继承PluginBase抽象类,并添加PluginEntrance属性。下面是一个插件入口的示例: Plugin.cs 在上面的代码中,我们定义了一个名为Plugin的类,并继承了 PluginBase抽象类。同时为Plugin类添加了PluginEntrance属性,以声..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-08-30T03:47:10.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-30T03:47:10.000Z"}],["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://docs.classisland.tech/dev/plugins/plugin-base.html"}]]},"git":{"createdTime":1724500283000,"updatedTime":1724989630000,"contributors":[{"name":"WRC","username":"WRC","email":"hello_wrc@outlook.com","commits":2,"url":"https://github.com/WRC"},{"name":"hello8693","username":"hello8693","email":"1320998105@qq.com","commits":1,"url":"https://github.com/hello8693"}]},"readingTime":{"minutes":1.64,"words":491},"filePathRelative":"en-us/dev/plugins/plugin-base.md","autoDesc":true}');export{o as comp,y as data};