Skip to content

Commit 3717bee

Browse files
authored
Merge pull request #65 from tgiachi/feature/plugin-loader
feat(plugin): add SquidStd.Plugin loader package
2 parents b8fb09b + cab036d commit 3717bee

30 files changed

Lines changed: 924 additions & 14 deletions

SquidStd.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<Project Path="src/SquidStd.Persistence/SquidStd.Persistence.csproj"/>
2424
<Project Path="src/SquidStd.Persistence.MessagePack/SquidStd.Persistence.MessagePack.csproj"/>
2525
<Project Path="src/SquidStd.Plugin.Abstractions/SquidStd.Plugin.Abstractions.csproj"/>
26+
<Project Path="src/SquidStd.Plugin/SquidStd.Plugin.csproj"/>
2627
<Project Path="src/SquidStd.Scripting.Lua/SquidStd.Scripting.Lua.csproj"/>
2728
<Project Path="src/SquidStd.Services.Core/SquidStd.Services.Core.csproj"/>
2829
<Project Path="src/SquidStd.Storage.Abstractions/SquidStd.Storage.Abstractions.csproj"/>

docs/articles/plugin.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[!include[](../../src/SquidStd.Plugin/README.md)]

docs/articles/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
href: network.md
4747
- name: SquidStd.Plugin.Abstractions
4848
href: plugin-abstractions.md
49+
- name: SquidStd.Plugin
50+
href: plugin.md
4951
- name: SquidStd.Database.Abstractions
5052
href: database-abstractions.md
5153
- name: SquidStd.Database

docs/tutorials/plugins.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ one plugin by hand so the contract is fully runnable without external assemblies
5252
## See also
5353

5454
- [SquidStd.Plugin.Abstractions reference](../articles/plugin-abstractions.md)
55+
- [SquidStd.Plugin reference](../articles/plugin.md) - the loader that discovers and configures plugins in dependency order

samples/SquidStd.Samples.Plugins/Program.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using DryIoc;
2+
using SquidStd.Core.Data.Bootstrap;
23
using SquidStd.Plugin.Abstractions.Data;
34
using SquidStd.Plugin.Abstractions.Interfaces.Plugins;
5+
using SquidStd.Plugin.Extensions;
6+
using SquidStd.Services.Core.Services.Bootstrap;
47

58
namespace SquidStd.Samples.Plugins;
69

@@ -41,16 +44,16 @@ private static void Main()
4144
{
4245
#region step-2
4346

44-
var container = new Container();
45-
var context = new PluginContext();
46-
context.Data["startedAt"] = DateTimeOffset.UtcNow;
47-
48-
ISquidStdPlugin plugin = new WeatherPlugin();
47+
var bootstrap = SquidStdBootstrap.Create(
48+
new SquidStdOptions { ConfigName = "plugins-sample", RootDirectory = Directory.GetCurrentDirectory() }
49+
);
4950

51+
var plugin = new WeatherPlugin();
5052
Console.WriteLine($"Loading {plugin.Metadata.Name} v{plugin.Metadata.Version} by {plugin.Metadata.Author}");
51-
plugin.Configure(container, context);
5253

53-
var greeter = container.Resolve<IGreeter>();
54+
bootstrap.UsePlugins(plugins => plugins.Add(plugin));
55+
56+
var greeter = bootstrap.Resolve<IGreeter>();
5457
Console.WriteLine(greeter.Greet("squid"));
5558

5659
#endregion

samples/SquidStd.Samples.Plugins/SquidStd.Samples.Plugins.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
<ItemGroup>
1212
<ProjectReference Include="..\..\src\SquidStd.Plugin.Abstractions\SquidStd.Plugin.Abstractions.csproj"/>
13+
<ProjectReference Include="..\..\src\SquidStd.Plugin\SquidStd.Plugin.csproj"/>
14+
<ProjectReference Include="..\..\src\SquidStd.Services.Core\SquidStd.Services.Core.csproj"/>
1315
</ItemGroup>
1416

1517
</Project>

src/SquidStd.Core/Interfaces/Bootstrap/ISquidStdBootstrap.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using DryIoc;
22
using SquidStd.Core.Data.Bootstrap;
33
using SquidStd.Core.Interfaces.Config;
4+
using SquidStd.Core.Types.Bootstrap;
45

56
namespace SquidStd.Core.Interfaces.Bootstrap;
67

@@ -19,6 +20,12 @@ public interface ISquidStdBootstrap : IAsyncDisposable
1920
/// </summary>
2021
IContainer Container { get; }
2122

23+
/// <summary>
24+
/// Gets the current lifecycle state of the bootstrap. Reads are lock-free and intended for
25+
/// pre-start guards, not for synchronizing concurrent lifecycle transitions.
26+
/// </summary>
27+
BootstrapStateType State { get; }
28+
2229
/// <summary>
2330
/// Applies custom service registrations before the bootstrap lifecycle starts.
2431
/// </summary>

src/SquidStd.Services.Core/Types/BootstrapStateType.cs renamed to src/SquidStd.Core/Types/Bootstrap/BootstrapStateType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
namespace SquidStd.Services.Core.Types;
1+
namespace SquidStd.Core.Types.Bootstrap;
22

33
/// <summary>
44
/// Lifecycle state of the SquidStd bootstrapper.
55
/// </summary>
6-
internal enum BootstrapStateType
6+
public enum BootstrapStateType
77
{
88
/// <summary>Created but not started.</summary>
99
Created,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace SquidStd.Plugin.Abstractions.Data;
2+
3+
/// <summary>
4+
/// Well-known keys the SquidStd plugin loader populates in <see cref="PluginContext.Data" />.
5+
/// </summary>
6+
public static class PluginContextKeys
7+
{
8+
/// <summary>
9+
/// Application root directory (string): the bootstrap RootDirectory option.
10+
/// </summary>
11+
public const string RootDirectory = "squidstd:rootDirectory";
12+
13+
/// <summary>
14+
/// Application name (string): the bootstrap AppName option when set, otherwise the entry
15+
/// assembly name, otherwise the bootstrap ConfigName.
16+
/// </summary>
17+
public const string AppName = "squidstd:appName";
18+
}

src/SquidStd.Plugin.Abstractions/Data/PluginMetadata.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
namespace SquidStd.Plugin.Abstractions.Data;
22

33
/// <summary>
4-
/// Describes a Moongate plugin. This is the source of truth for plugin identity.
4+
/// Describes a SquidStd plugin. This is the source of truth for plugin identity.
55
/// </summary>
66
public sealed class PluginMetadata
77
{
8-
/// <summary>Stable lowercase dotted plugin identifier, for example <c>moongate.weather</c>.</summary>
8+
/// <summary>Stable lowercase dotted plugin identifier, for example <c>myapp.weather</c>.</summary>
99
public required string Id { get; init; }
1010

1111
/// <summary>Human-readable plugin name.</summary>

0 commit comments

Comments
 (0)