using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using LANCommander.SDK.Helpers; namespace LANCommander.SDK.Plugins; /// /// Convenience helper that centralizes plugin discovery so every host wires it identically. /// Call as the last step while populating the service collection /// (before building the provider), then call /// on the returned loader after the provider is built. /// public static class PluginBootstrap { /// Name of the drop-in folder under the host's config directory. public const string PluginsFolderName = "Plugins"; /// /// Discovers plugins for from <config>/Plugins, lets each register /// its services into , and registers the loader as a singleton so the /// same instance can drive Phase 2 initialization. /// public static PluginLoaderService ConfigurePlugins(IServiceCollection services, PluginHost host) { var loader = new PluginLoaderService(); // Discovery runs before the host's provider exists, so use a throwaway logger factory just for // discovery diagnostics. Phase 2 uses the host's real logger factory. using (var loggerFactory = LoggerFactory.Create(builder => builder.AddSimpleConsole())) { var logger = loggerFactory.CreateLogger("LANCommander.Plugins"); var pluginsRoot = AppPaths.GetConfigPath(PluginsFolderName); var hostVersion = VersionHelper.GetCurrentVersion().ToString(); loader.DiscoverAndConfigure(services, host, pluginsRoot, hostVersion, logger); } services.AddSingleton(loader); return loader; } }