修改 CloudProduct ImageCache 项目改为 插件
This commit is contained in:
1 parent
5ff52dea92
commit
292cb8638c
26 files changed
+417
-282
No files matched your search
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace MAX.Plugins;
|
||||
|
||||
public abstract class PluginBase : IPlugin
|
||||
{
|
||||
public abstract string Id { get; }
|
||||
public virtual int Priority => 0;
|
||||
protected PluginContext Context { get; private set; } = null!;
|
||||
|
||||
public void ConfigureServices(IServiceCollection services, PluginContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(services);
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
if (!string.Equals(Id, context.Id, StringComparison.Ordinal))
|
||||
throw new ArgumentException("插件上下文标识不匹配。", nameof(context));
|
||||
if (Context is not null) throw new InvalidOperationException($"插件 {Id} 已注册。");
|
||||
Context = context;
|
||||
RegisterServices(services);
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, PluginContext context)
|
||||
{
|
||||
if (!ReferenceEquals(Context, context))
|
||||
throw new InvalidOperationException($"插件 {Id} 尚未注册或上下文不匹配。");
|
||||
ConfigureApplication(app);
|
||||
}
|
||||
protected abstract void RegisterServices(IServiceCollection services);
|
||||
protected virtual void ConfigureApplication(IApplicationBuilder app) { }
|
||||
protected string RequireConfiguration(string key) => Context.RequireConfiguration(key);
|
||||
}
|
||||
Reference in new issue
Block a user