a sample plugin application of blazor.
- Create a razor library
- Make the library reference the project
Davis.Core
- Create a Component as the plugin entry point
- Make the component implement the interface
Davis.Core.IDavisPlugin
. Note that there can only be one component that implements theDavis.Core.IDavisPlugin
interface in the razor library. - Then, write your code.
- Create a
_meta.json
file, to store metadata describing plugins:
{
"name": "plugin's name", // required field
"version": "1.0.0", // plugin's version
"author": "plugin's author",
"description": "plugin's description",
"tags": [ "c#", "Bootstrap Plugin", "Regex" ] // plugin's tags
}
More see the sample: sample/CsRegexPlugin
and sample/MessagePlugin
.
- Make sure the js and css file in the
wwwroot
directory. - Use CascadingParameter
IPluginContext
in the component. - Load css or js in the
SetParametersAsync
method, and unload css or js in theDispose
.
@implements Davis.Core.IDavisPlugin
@implements IDisposable
<div>
</div>
@code {
[CascadingParameter]
public Davis.Core.IPluginContext Context { get; set; } = default!;
public override async Task SetParametersAsync(ParameterView parameters)
{
await base.SetParametersAsync(parameters);
// assets/index.js and assets/index.css both in the wwwroot directory
await Context.LoadJs("assets/index.js");
await Context.LoadCss("assets/index.css");
}
public void Dispose()
{
_ = Context.UnLoadJs("assets/index.js");
_ = Context.UnLoadCss("assets/index.css");
}
}
- publish the library to a directory, assuming that this directory is named
publish
- copy the
publish
directory to thePlugins
directory of Davis, and modify the namepulish
to plugin name. - make the the razor library dll name is same with the plugin name.
- Run Davis application.
- Photino.Blazor
- AntDesign
- Blazored.SessionStorage
- Jil
- Bootstrap
Apache 2.0