-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathCustomPlugin.cs
More file actions
27 lines (22 loc) · 987 Bytes
/
Copy pathCustomPlugin.cs
File metadata and controls
27 lines (22 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
namespace ServiceStack;
/// <summary>
/// Allow custom AppHost registrations to run at different plugin lifecycle events
/// </summary>
public class CustomPlugin : IPlugin, Model.IHasStringId, IPreInitPlugin, IPostInitPlugin
{
public string Id { get; set; } = "Custom";
public Action<IAppHost> OnRegister { get; set; }
public Action<IAppHost> OnBeforePluginsLoaded { get; set; }
public Action<IAppHost> OnAfterPluginsLoaded { get; set; }
public CustomPlugin() { }
public CustomPlugin(Action<IAppHost> onRegister) : this("Custom", onRegister) {}
public CustomPlugin(string id, Action<IAppHost> onRegister)
{
this.OnRegister = onRegister;
Id = id;
}
public void Register(IAppHost appHost) => OnRegister?.Invoke(appHost);
public void BeforePluginsLoaded(IAppHost appHost) => OnBeforePluginsLoaded?.Invoke(appHost);
public void AfterPluginsLoaded(IAppHost appHost) => OnAfterPluginsLoaded?.Invoke(appHost);
}